Skip to content

Commit

Permalink
Merge branch 'master' into update-versions-v1.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph committed Dec 2, 2024
2 parents 3a13b24 + 912f6f9 commit 6c67c35
Show file tree
Hide file tree
Showing 22 changed files with 172 additions and 161 deletions.
2 changes: 0 additions & 2 deletions api/info/service.md
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,6 @@ info.peers({
lastReceived: string,
benched: string[],
observedUptime: int,
observedSubnetUptime: map[string]int,
}
}
```
Expand Down Expand Up @@ -558,7 +557,6 @@ curl -X POST --data '{
"lastReceived": "2020-06-01T15:22:57Z",
"benched": [],
"observedUptime": "99",
"observedSubnetUptimes": {},
"trackedSubnets": [],
"benched": []
},
Expand Down
12 changes: 4 additions & 8 deletions vms/example/xsvm/cmd/chain/create/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ func createFunc(c *cobra.Command, args []string) error {
ctx := c.Context()
kc := secp256k1fx.NewKeychain(config.PrivateKey)

// NewWalletFromURI fetches the available UTXOs owned by [kc] on the network
// that [uri] is hosting.
// MakePWallet fetches the available UTXOs owned by [kc] on the P-chain that
// [uri] is hosting.
walletSyncStartTime := time.Now()
wallet, err := primary.MakeWallet(
wallet, err := primary.MakePWallet(
ctx,
config.URI,
kc,
kc,
primary.WalletConfig{
SubnetIDs: []ids.ID{config.SubnetID},
},
Expand All @@ -55,9 +54,6 @@ func createFunc(c *cobra.Command, args []string) error {
}
log.Printf("synced wallet in %s\n", time.Since(walletSyncStartTime))

// Get the P-chain wallet
pWallet := wallet.P()

genesisBytes, err := genesis.Codec.Marshal(genesis.CodecVersion, &genesis.Genesis{
Timestamp: 0,
Allocations: []genesis.Allocation{
Expand All @@ -72,7 +68,7 @@ func createFunc(c *cobra.Command, args []string) error {
}

createChainStartTime := time.Now()
createChainTxID, err := pWallet.IssueCreateChainTx(
createChainTxID, err := wallet.IssueCreateChainTx(
config.SubnetID,
genesisBytes,
constants.XSVMID,
Expand Down
12 changes: 11 additions & 1 deletion vms/platformvm/block/executor/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import (
var (
_ Manager = (*manager)(nil)

ErrChainNotSynced = errors.New("chain not synced")
ErrChainNotSynced = errors.New("chain not synced")
ErrImportTxWhilePartialSyncing = errors.New("issuing an import tx is not allowed while partial syncing")
)

type Manager interface {
Expand Down Expand Up @@ -124,6 +125,15 @@ func (m *manager) VerifyTx(tx *txs.Tx) error {
return ErrChainNotSynced
}

// If partial sync is enabled, this node isn't guaranteed to have the full
// UTXO set from shared memory. To avoid issuing invalid transactions,
// issuance of an ImportTx during this state is completely disallowed.
if m.txExecutorBackend.Config.PartialSyncPrimaryNetwork {
if _, isImportTx := tx.Unsigned.(*txs.ImportTx); isImportTx {
return ErrImportTxWhilePartialSyncing
}
}

recommendedPChainHeight, err := m.ctx.ValidatorState.GetMinimumHeight(context.TODO())
if err != nil {
return fmt.Errorf("failed to fetch P-chain height: %w", err)
Expand Down
26 changes: 26 additions & 0 deletions vms/platformvm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,3 +687,29 @@ func GetDeactivationOwners(
}
return deactivationOwners, nil
}

// GetOwners returns the union of GetSubnetOwners and GetDeactivationOwners.
func GetOwners(
c Client,
ctx context.Context,
subnetIDs []ids.ID,
validationIDs []ids.ID,
) (map[ids.ID]fx.Owner, error) {
subnetOwners, err := GetSubnetOwners(c, ctx, subnetIDs...)
if err != nil {
return nil, err
}
deactivationOwners, err := GetDeactivationOwners(c, ctx, validationIDs...)
if err != nil {
return nil, err
}

owners := make(map[ids.ID]fx.Owner, len(subnetOwners)+len(deactivationOwners))
for id, owner := range subnetOwners {
owners[id] = owner
}
for id, owner := range deactivationOwners {
owners[id] = owner
}
return owners, nil
}
22 changes: 2 additions & 20 deletions vms/platformvm/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package network

import (
"context"
"errors"
"sync"
"time"

Expand All @@ -26,8 +25,6 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/warp"
)

var errMempoolDisabledWithPartialSync = errors.New("mempool is disabled partial syncing")

type Network struct {
*p2p.Network

Expand Down Expand Up @@ -188,18 +185,12 @@ func New(
}

func (n *Network) PushGossip(ctx context.Context) {
// TODO: Even though the node is running partial sync, we should support
// issuing transactions from the RPC.
if n.partialSyncPrimaryNetwork {
return
}

gossip.Every(ctx, n.log, n.txPushGossiper, n.txPushGossipFrequency)
}

func (n *Network) PullGossip(ctx context.Context) {
// If the node is running partial sync, we should not perform any pull
// gossip.
// If the node is running partial sync, we do not perform any pull gossip
// because we should never be a validator.
if n.partialSyncPrimaryNetwork {
return
}
Expand All @@ -219,15 +210,6 @@ func (n *Network) AppGossip(ctx context.Context, nodeID ids.NodeID, msgBytes []b
}

func (n *Network) IssueTxFromRPC(tx *txs.Tx) error {
// If we are partially syncing the Primary Network, we should not be
// maintaining the transaction mempool locally.
//
// TODO: We should still push the transaction to some peers when partial
// syncing.
if n.partialSyncPrimaryNetwork {
return errMempoolDisabledWithPartialSync
}

if err := n.mempool.Add(tx); err != nil {
return err
}
Expand Down
24 changes: 6 additions & 18 deletions vms/platformvm/network/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ func TestNetworkIssueTxFromRPC(t *testing.T) {
tx := &txs.Tx{}

type test struct {
name string
mempoolFunc func(*gomock.Controller) pmempool.Mempool
txVerifier testTxVerifier
partialSyncPrimaryNetwork bool
appSenderFunc func(*gomock.Controller) common.AppSender
expectedErr error
name string
mempoolFunc func(*gomock.Controller) pmempool.Mempool
txVerifier testTxVerifier
appSenderFunc func(*gomock.Controller) common.AppSender
expectedErr error
}

tests := []test{
Expand Down Expand Up @@ -129,17 +128,6 @@ func TestNetworkIssueTxFromRPC(t *testing.T) {
},
expectedErr: errTest,
},
{
name: "mempool is disabled if primary network is not being fully synced",
mempoolFunc: func(ctrl *gomock.Controller) pmempool.Mempool {
return mempoolmock.NewMempool(ctrl)
},
partialSyncPrimaryNetwork: true,
appSenderFunc: func(ctrl *gomock.Controller) common.AppSender {
return commonmock.NewSender(ctrl)
},
expectedErr: errMempoolDisabledWithPartialSync,
},
{
name: "happy path",
mempoolFunc: func(ctrl *gomock.Controller) pmempool.Mempool {
Expand Down Expand Up @@ -174,7 +162,7 @@ func TestNetworkIssueTxFromRPC(t *testing.T) {
snowCtx.ValidatorState,
tt.txVerifier,
tt.mempoolFunc(ctrl),
tt.partialSyncPrimaryNetwork,
false,
tt.appSenderFunc(ctrl),
nil,
nil,
Expand Down
20 changes: 9 additions & 11 deletions wallet/chain/p/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"context"

"github.com/ava-labs/avalanchego/api/info"
"github.com/ava-labs/avalanchego/vms/avm"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/vms/platformvm"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/fee"
"github.com/ava-labs/avalanchego/wallet/chain/p/builder"
Expand All @@ -21,42 +21,40 @@ const gasPriceMultiplier = 2

func NewContextFromURI(ctx context.Context, uri string) (*builder.Context, error) {
infoClient := info.NewClient(uri)
xChainClient := avm.NewClient(uri, "X")
pChainClient := platformvm.NewClient(uri)
return NewContextFromClients(ctx, infoClient, xChainClient, pChainClient)
chainClient := platformvm.NewClient(uri)
return NewContextFromClients(ctx, infoClient, chainClient)
}

func NewContextFromClients(
ctx context.Context,
infoClient info.Client,
xChainClient avm.Client,
pChainClient platformvm.Client,
chainClient platformvm.Client,
) (*builder.Context, error) {
networkID, err := infoClient.GetNetworkID(ctx)
if err != nil {
return nil, err
}

asset, err := xChainClient.GetAssetDescription(ctx, "AVAX")
avaxAssetID, err := chainClient.GetStakingAssetID(ctx, constants.PrimaryNetworkID)
if err != nil {
return nil, err
}

dynamicFeeConfig, err := pChainClient.GetFeeConfig(ctx)
dynamicFeeConfig, err := chainClient.GetFeeConfig(ctx)
if err != nil {
return nil, err
}

// TODO: After Etna is activated, assume the gas price is always non-zero.
if dynamicFeeConfig.MinPrice != 0 {
_, gasPrice, _, err := pChainClient.GetFeeState(ctx)
_, gasPrice, _, err := chainClient.GetFeeState(ctx)
if err != nil {
return nil, err
}

return &builder.Context{
NetworkID: networkID,
AVAXAssetID: asset.AssetID,
AVAXAssetID: avaxAssetID,
ComplexityWeights: dynamicFeeConfig.Weights,
GasPrice: gasPriceMultiplier * gasPrice,
}, nil
Expand All @@ -69,7 +67,7 @@ func NewContextFromClients(

return &builder.Context{
NetworkID: networkID,
AVAXAssetID: asset.AssetID,
AVAXAssetID: avaxAssetID,
StaticFeeConfig: fee.StaticConfig{
TxFee: uint64(staticFeeConfig.TxFee),
CreateSubnetTxFee: uint64(staticFeeConfig.CreateSubnetTxFee),
Expand Down
34 changes: 33 additions & 1 deletion wallet/subnet/primary/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func FetchState(
xClient := avm.NewClient(uri, "X")
cClient := evm.NewCChainClient(uri)

pCTX, err := p.NewContextFromClients(ctx, infoClient, xClient, pClient)
pCTX, err := p.NewContextFromClients(ctx, infoClient, pClient)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -145,6 +145,38 @@ func FetchState(
}, nil
}

func FetchPState(
ctx context.Context,
uri string,
addrs set.Set[ids.ShortID],
) (
platformvm.Client,
*pbuilder.Context,
walletcommon.UTXOs,
error,
) {
infoClient := info.NewClient(uri)
chainClient := platformvm.NewClient(uri)

context, err := p.NewContextFromClients(ctx, infoClient, chainClient)
if err != nil {
return nil, nil, nil, err
}

utxos := walletcommon.NewUTXOs()
addrList := addrs.List()
err = AddAllUTXOs(
ctx,
utxos,
chainClient,
txs.Codec,
constants.PlatformChainID,
constants.PlatformChainID,
addrList,
)
return chainClient, context, utxos, err
}

type EthState struct {
Client ethclient.Client
Accounts map[ethcommon.Address]*c.Account
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@ func main() {
}
log.Printf("fetched node ID %s in %s\n", nodeID, time.Since(nodeInfoStartTime))

// MakeWallet fetches the available UTXOs owned by [kc] on the network that
// MakePWallet fetches the available UTXOs owned by [kc] on the P-chain that
// [uri] is hosting and registers [subnetID].
walletSyncStartTime := time.Now()
wallet, err := primary.MakeWallet(
wallet, err := primary.MakePWallet(
ctx,
uri,
kc,
kc,
primary.WalletConfig{
SubnetIDs: []ids.ID{subnetID},
},
Expand All @@ -58,11 +57,8 @@ func main() {
}
log.Printf("synced wallet in %s\n", time.Since(walletSyncStartTime))

// Get the P-chain wallet
pWallet := wallet.P()

addValidatorStartTime := time.Now()
addValidatorTx, err := pWallet.IssueAddSubnetValidatorTx(&txs.SubnetValidator{
addValidatorTx, err := wallet.IssueAddSubnetValidatorTx(&txs.SubnetValidator{
Validator: txs.Validator{
NodeID: nodeID,
Start: uint64(startTime.Unix()),
Expand Down
16 changes: 6 additions & 10 deletions wallet/subnet/primary/examples/add-primary-validator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,33 @@ func main() {
}
log.Printf("fetched node ID %s in %s\n", nodeID, time.Since(nodeInfoStartTime))

// MakeWallet fetches the available UTXOs owned by [kc] on the network that
// MakePWallet fetches the available UTXOs owned by [kc] on the P-chain that
// [uri] is hosting.
walletSyncStartTime := time.Now()
wallet, err := primary.MakeWallet(
wallet, err := primary.MakePWallet(
ctx,
uri,
kc,
kc,
primary.WalletConfig{},
)
if err != nil {
log.Fatalf("failed to initialize wallet: %s\n", err)
}
log.Printf("synced wallet in %s\n", time.Since(walletSyncStartTime))

// Get the P-chain wallet
pWallet := wallet.P()
pBuilder := pWallet.Builder()
pContext := pBuilder.Context()
avaxAssetID := pContext.AVAXAssetID
// Get the chain context
context := wallet.Builder().Context()

addValidatorStartTime := time.Now()
addValidatorTx, err := pWallet.IssueAddPermissionlessValidatorTx(
addValidatorTx, err := wallet.IssueAddPermissionlessValidatorTx(
&txs.SubnetValidator{Validator: txs.Validator{
NodeID: nodeID,
Start: uint64(startTime.Unix()),
End: uint64(startTime.Add(duration).Unix()),
Wght: weight,
}},
nodePOP,
avaxAssetID,
context.AVAXAssetID,
&secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{validatorRewardAddr},
Expand Down
Loading

0 comments on commit 6c67c35

Please sign in to comment.