From dce85fdfb5d299f8a9395dd747aecb6f6afa83e2 Mon Sep 17 00:00:00 2001 From: tsachiherman <24438559+tsachiherman@users.noreply.github.com> Date: Tue, 20 Aug 2024 11:56:23 -0400 Subject: [PATCH 01/17] update --- genesis/config.go | 2 +- genesis/unparsed_config.go | 2 +- ids/node_id.go | 64 +---- ids/node_id_test.go | 28 +- ids/short_node_id.go | 104 ++++++++ ids/short_node_id_test.go | 251 ++++++++++++++++++ ids/test_generator.go | 15 +- .../common/appsender/appsender_client.go | 2 +- tests/fixture/tmpnet/genesis.go | 7 +- utils/ips/claimed_ip_port.go | 2 +- vms/platformvm/api/static_service.go | 14 +- vms/platformvm/api/static_service_test.go | 8 +- vms/platformvm/block/builder/helpers_test.go | 6 +- vms/platformvm/block/executor/helpers_test.go | 6 +- .../block/executor/proposal_block_test.go | 14 +- .../block/executor/standard_block_test.go | 14 +- vms/platformvm/service_test.go | 10 +- .../state/disk_staker_diff_iterator.go | 2 +- .../txs/executor/advance_time_test.go | 14 +- vms/platformvm/txs/executor/helpers_test.go | 6 +- .../txs/executor/proposal_tx_executor_test.go | 24 +- .../txs/executor/standard_tx_executor_test.go | 26 +- .../validators/manager_benchmark_test.go | 2 +- vms/platformvm/vm_regression_test.go | 22 +- vms/platformvm/vm_test.go | 28 +- wallet/subnet/primary/example_test.go | 4 +- 26 files changed, 508 insertions(+), 169 deletions(-) create mode 100644 ids/short_node_id.go create mode 100644 ids/short_node_id_test.go diff --git a/genesis/config.go b/genesis/config.go index 4ecd5f53b12a..901e9b872944 100644 --- a/genesis/config.go +++ b/genesis/config.go @@ -65,7 +65,7 @@ func (a Allocation) Compare(other Allocation) int { } type Staker struct { - NodeID ids.NodeID `json:"nodeID"` + NodeID ids.ShortNodeID `json:"nodeID"` RewardAddress ids.ShortID `json:"rewardAddress"` DelegationFee uint32 `json:"delegationFee"` Signer *signer.ProofOfPossession `json:"signer,omitempty"` diff --git a/genesis/unparsed_config.go b/genesis/unparsed_config.go index 2ace7647c363..a566cf91f258 100644 --- a/genesis/unparsed_config.go +++ b/genesis/unparsed_config.go @@ -55,7 +55,7 @@ func (ua UnparsedAllocation) Parse() (Allocation, error) { } type UnparsedStaker struct { - NodeID ids.NodeID `json:"nodeID"` + NodeID ids.ShortNodeID `json:"nodeID"` RewardAddress string `json:"rewardAddress"` DelegationFee uint32 `json:"delegationFee"` Signer *signer.ProofOfPossession `json:"signer,omitempty"` diff --git a/ids/node_id.go b/ids/node_id.go index 7e9e94a12cdd..7695d642742c 100644 --- a/ids/node_id.go +++ b/ids/node_id.go @@ -4,10 +4,6 @@ package ids import ( - "bytes" - "errors" - "fmt" - "github.com/ava-labs/avalanchego/staking" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/hashing" @@ -21,65 +17,27 @@ const ( var ( EmptyNodeID = NodeID{} - errShortNodeID = errors.New("insufficient NodeID length") - _ utils.Sortable[NodeID] = NodeID{} ) -type NodeID ShortID - -func (id NodeID) String() string { - return ShortID(id).PrefixedString(NodeIDPrefix) -} - -func (id NodeID) Bytes() []byte { - return id[:] -} - -func (id NodeID) MarshalJSON() ([]byte, error) { - return []byte(`"` + id.String() + `"`), nil -} - -func (id NodeID) MarshalText() ([]byte, error) { - return []byte(id.String()), nil -} - -func (id *NodeID) UnmarshalJSON(b []byte) error { - str := string(b) - if str == nullStr { // If "null", do nothing - return nil - } else if len(str) <= 2+len(NodeIDPrefix) { - return fmt.Errorf("%w: expected to be > %d", errShortNodeID, 2+len(NodeIDPrefix)) - } - - lastIndex := len(str) - 1 - if str[0] != '"' || str[lastIndex] != '"' { - return errMissingQuotes - } - - var err error - *id, err = NodeIDFromString(str[1:lastIndex]) - return err -} - -func (id *NodeID) UnmarshalText(text []byte) error { - return id.UnmarshalJSON(text) -} - -func (id NodeID) Compare(other NodeID) int { - return bytes.Compare(id[:], other[:]) +type NodeID struct { + ShortNodeID } // ToNodeID attempt to convert a byte slice into a node id func ToNodeID(bytes []byte) (NodeID, error) { nodeID, err := ToShortID(bytes) - return NodeID(nodeID), err + return NodeID{ShortNodeID: ShortNodeID(nodeID)}, err +} + +func (id NodeID) Compare(other NodeID) int { + return id.ShortNodeID.Compare(other.ShortNodeID) } func NodeIDFromCert(cert *staking.Certificate) NodeID { - return hashing.ComputeHash160Array( - hashing.ComputeHash256(cert.Raw), - ) + return NodeID{ + ShortNodeID: ShortNodeID(hashing.ComputeHash160Array(hashing.ComputeHash256(cert.Raw))), + } } // NodeIDFromString is the inverse of NodeID.String() @@ -88,5 +46,5 @@ func NodeIDFromString(nodeIDStr string) (NodeID, error) { if err != nil { return NodeID{}, err } - return NodeID(asShort), nil + return NodeID{ShortNodeID: ShortNodeID(asShort)}, nil } diff --git a/ids/node_id_test.go b/ids/node_id_test.go index 2c94450f5b66..6b3dfca29d8d 100644 --- a/ids/node_id_test.go +++ b/ids/node_id_test.go @@ -16,8 +16,8 @@ import ( func TestNodeIDEquality(t *testing.T) { require := require.New(t) - id := NodeID{24} - idCopy := NodeID{24} + id := NodeID{ShortNodeID: ShortNodeID{24}} + idCopy := NodeID{ShortNodeID: ShortNodeID{24}} require.Equal(id, idCopy) id2 := NodeID{} require.NotEqual(id, id2) @@ -26,7 +26,7 @@ func TestNodeIDEquality(t *testing.T) { func TestNodeIDFromString(t *testing.T) { require := require.New(t) - id := NodeID{'a', 'v', 'a', ' ', 'l', 'a', 'b', 's'} + id := NodeID{ShortNodeID: ShortNodeID{'a', 'v', 'a', ' ', 'l', 'a', 'b', 's'}} idStr := id.String() id2, err := NodeIDFromString(idStr) require.NoError(err) @@ -76,7 +76,7 @@ func TestNodeIDMarshalJSON(t *testing.T) { }, { `ID("ava labs")`, - NodeID{'a', 'v', 'a', ' ', 'l', 'a', 'b', 's'}, + NodeID{ShortNodeID: ShortNodeID{'a', 'v', 'a', ' ', 'l', 'a', 'b', 's'}}, []byte(`"NodeID-9tLMkeWFhWXd8QZc4rSiS5meuVXF5kRsz"`), nil, }, @@ -108,7 +108,7 @@ func TestNodeIDUnmarshalJSON(t *testing.T) { { `NodeID("ava labs")`, []byte(`"NodeID-9tLMkeWFhWXd8QZc4rSiS5meuVXF5kRsz"`), - NodeID{'a', 'v', 'a', ' ', 'l', 'a', 'b', 's'}, + NodeID{ShortNodeID: ShortNodeID{'a', 'v', 'a', ' ', 'l', 'a', 'b', 's'}}, nil, }, { @@ -161,7 +161,7 @@ func TestNodeIDString(t *testing.T) { expected string }{ {"NodeID{}", NodeID{}, "NodeID-111111111111111111116DBWJs"}, - {"NodeID{24}", NodeID{24}, "NodeID-3BuDc2d1Efme5Apba6SJ8w3Tz7qeh6mHt"}, + {"NodeID{24}", NodeID{ShortNodeID: ShortNodeID{24}}, "NodeID-3BuDc2d1Efme5Apba6SJ8w3Tz7qeh6mHt"}, } for _, tt := range tests { t.Run(tt.label, func(t *testing.T) { @@ -174,8 +174,8 @@ func TestNodeIDMapMarshalling(t *testing.T) { require := require.New(t) originalMap := map[NodeID]int{ - {'e', 'v', 'a', ' ', 'l', 'a', 'b', 's'}: 1, - {'a', 'v', 'a', ' ', 'l', 'a', 'b', 's'}: 2, + {ShortNodeID: ShortNodeID{'a', 'v', 'a', ' ', 'l', 'a', 'b', 's'}}: 1, + {ShortNodeID: ShortNodeID{'a', 'v', 'a', ' ', 'l', 'a', 'b', 's'}}: 2, } mapJSON, err := json.Marshal(originalMap) require.NoError(err) @@ -192,18 +192,18 @@ func TestNodeIDCompare(t *testing.T) { expected int }{ { - a: NodeID{1}, - b: NodeID{0}, + a: NodeID{ShortNodeID: ShortNodeID{1}}, + b: NodeID{ShortNodeID: ShortNodeID{0}}, expected: 1, }, { - a: NodeID{1}, - b: NodeID{1}, + a: NodeID{ShortNodeID: ShortNodeID{1}}, + b: NodeID{ShortNodeID: ShortNodeID{1}}, expected: 0, }, { - a: NodeID{1, 0}, - b: NodeID{1, 2}, + a: NodeID{ShortNodeID: ShortNodeID{1, 0}}, + b: NodeID{ShortNodeID: ShortNodeID{1, 2}}, expected: -1, }, } diff --git a/ids/short_node_id.go b/ids/short_node_id.go new file mode 100644 index 000000000000..00e26f4855e5 --- /dev/null +++ b/ids/short_node_id.go @@ -0,0 +1,104 @@ +// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package ids + +import ( + "bytes" + "errors" + "fmt" + + "github.com/ava-labs/avalanchego/staking" + "github.com/ava-labs/avalanchego/utils" + "github.com/ava-labs/avalanchego/utils/hashing" +) + +const ShortNodeIDLen = ShortIDLen + +var ( + EmptyShortNodeID = ShortNodeID{} + + errShortNodeID = errors.New("insufficient ShortNodeID length") + + _ utils.Sortable[ShortNodeID] = ShortNodeID{} +) + +type ShortNodeID ShortID + +func (sn ShortNodeID) Bytes() []byte { + return sn[:] +} + +func ToShortNodeID(bytes []byte) (ShortNodeID, error) { + nodeID, err := ToShortID(bytes) + return ShortNodeID(nodeID), err +} + +func (sn ShortNodeID) String() string { + return ShortID(sn).PrefixedString(NodeIDPrefix) +} + +// ShortNodeIDFromString is the inverse of ShortNodeID.String() +func ShortNodeIDFromString(nodeIDStr string) (ShortNodeID, error) { + asShort, err := ShortFromPrefixedString(nodeIDStr, NodeIDPrefix) + if err != nil { + return EmptyShortNodeID, err + } + return ShortNodeID(asShort), nil +} + +// ShortNodeIDFromNodeID is the inverse of NodeID.String() +func ShortNodeIDFromNodeID(nodeID NodeID) (ShortNodeID, error) { + if nodeID == EmptyNodeID { + return EmptyShortNodeID, nil + } + res, err := ToShortNodeID(nodeID.Bytes()) + if err != nil { + return EmptyShortNodeID, fmt.Errorf("failed converting NodeID to ShortNodeID, %w", err) + } + return res, nil +} + +func (sn ShortNodeID) MarshalJSON() ([]byte, error) { + return []byte(`"` + sn.String() + `"`), nil +} + +func (sn *ShortNodeID) UnmarshalJSON(b []byte) error { + str := string(b) + if str == nullStr { // If "null", do nothing + return nil + } else if len(str) <= 2+len(NodeIDPrefix) { + return fmt.Errorf("%w: expected to be > %d", errShortNodeID, 2+len(NodeIDPrefix)) + } + + lastIndex := len(str) - 1 + if str[0] != '"' || str[lastIndex] != '"' { + return errMissingQuotes + } + + var err error + *sn, err = ShortNodeIDFromString(str[1:lastIndex]) + return err +} + +func (sn ShortNodeID) MarshalText() ([]byte, error) { + return []byte(sn.String()), nil +} + +func (sn *ShortNodeID) UnmarshalText(text []byte) error { + return sn.UnmarshalJSON(text) +} + +func (sn ShortNodeID) Compare(other ShortNodeID) int { + return bytes.Compare(sn[:], other[:]) +} + +func (sn ShortNodeID) NodeID() NodeID { + return NodeID{ShortNodeID: sn} +} + +func ShortNodeIDFromCert(cert *staking.Certificate) ShortNodeID { + return hashing.ComputeHash160Array( + hashing.ComputeHash256(cert.Raw), + ) +} diff --git a/ids/short_node_id_test.go b/ids/short_node_id_test.go new file mode 100644 index 000000000000..d7708d3491ba --- /dev/null +++ b/ids/short_node_id_test.go @@ -0,0 +1,251 @@ +// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package ids + +import ( + "encoding/json" + "fmt" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/ava-labs/avalanchego/utils/cb58" +) + +func TestShortNodeIDEquality(t *testing.T) { + require := require.New(t) + + id := ShortNodeID{24} + idCopy := ShortNodeID{24} + require.Equal(id, idCopy) + id2 := EmptyShortNodeID + require.NotEqual(id, id2) +} + +func TestShortIDBytesIsolation(t *testing.T) { + require := require.New(t) + + id := ShortID{24} + idBytes := id.Bytes() + idBytes[0] = 25 + require.Equal(ShortID{24}, id) +} + +func TestShortNodeIDBytesIsolation(t *testing.T) { + require := require.New(t) + + id := ShortNodeID{24} + idBytes := id.Bytes() + idBytes[0] = 25 + require.Equal(ShortNodeID{24}, id) +} + +func TestShortNodeIDFromString(t *testing.T) { + require := require.New(t) + + id := ShortNodeID{'a', 'v', 'a', ' ', 'l', 'a', 'b', 's'} + idStr := id.String() + id2, err := ShortNodeIDFromString(idStr) + require.NoError(err) + require.Equal(id, id2) + expected := "NodeID-9tLMkeWFhWXd8QZc4rSiS5meuVXF5kRsz" + require.Equal(expected, idStr) +} + +func TestShortNodeIDFromStringError(t *testing.T) { + tests := []struct { + in string + expectedErr error + }{ + { + in: "", + expectedErr: cb58.ErrBase58Decoding, + }, + { + in: "foo", + expectedErr: cb58.ErrMissingChecksum, + }, + { + in: "foobar", + expectedErr: cb58.ErrBadChecksum, + }, + } + for _, tt := range tests { + t.Run(tt.in, func(t *testing.T) { + _, err := FromString(tt.in) + require.ErrorIs(t, err, tt.expectedErr) + }) + } +} + +func TestShortNodeIDMarshalJSON(t *testing.T) { + tests := []struct { + label string + in ShortNodeID + out []byte + err error + }{ + { + "NodeID{}", + ShortNodeID{}, + []byte(`"NodeID-111111111111111111116DBWJs"`), + nil, + }, + { + `ID("ava labs")`, + ShortNodeID{'a', 'v', 'a', ' ', 'l', 'a', 'b', 's'}, + []byte(`"NodeID-9tLMkeWFhWXd8QZc4rSiS5meuVXF5kRsz"`), + nil, + }, + } + for _, tt := range tests { + t.Run(tt.label, func(t *testing.T) { + require := require.New(t) + + out, err := tt.in.MarshalJSON() + require.ErrorIs(err, tt.err) + require.Equal(tt.out, out) + }) + } +} + +func TestShortNodeIDUnmarshalJSON(t *testing.T) { + tests := []struct { + label string + in []byte + out ShortNodeID + expectedErr error + }{ + { + "NodeID{}", + []byte("null"), + ShortNodeID{}, + nil, + }, + { + `NodeID("ava labs")`, + []byte(`"NodeID-9tLMkeWFhWXd8QZc4rSiS5meuVXF5kRsz"`), + ShortNodeID{'a', 'v', 'a', ' ', 'l', 'a', 'b', 's'}, + nil, + }, + { + "missing start quote", + []byte(`NodeID-9tLMkeWFhWXd8QZc4rSiS5meuVXF5kRsz"`), + ShortNodeID{}, + errMissingQuotes, + }, + { + "missing end quote", + []byte(`"NodeID-9tLMkeWFhWXd8QZc4rSiS5meuVXF5kRsz`), + ShortNodeID{}, + errMissingQuotes, + }, + { + "NodeID-", + []byte(`"NodeID-"`), + ShortNodeID{}, + errShortNodeID, + }, + { + "NodeID-1", + []byte(`"NodeID-1"`), + ShortNodeID{}, + cb58.ErrMissingChecksum, + }, + { + "NodeID-9tLMkeWFhWXd8QZc4rSiS5meuVXF5kRsz1", + []byte(`"NodeID-1"`), + ShortNodeID{}, + cb58.ErrMissingChecksum, + }, + } + for _, tt := range tests { + t.Run(tt.label, func(t *testing.T) { + require := require.New(t) + + foo := ShortNodeID{} + err := foo.UnmarshalJSON(tt.in) + require.ErrorIs(err, tt.expectedErr) + require.Equal(tt.out, foo) + }) + } +} + +func TestShortNodeIDString(t *testing.T) { + tests := []struct { + label string + id ShortNodeID + expected string + }{ + {"NodeID{}", EmptyShortNodeID, "NodeID-111111111111111111116DBWJs"}, + {"NodeID{24}", ShortNodeID{24}, "NodeID-3BuDc2d1Efme5Apba6SJ8w3Tz7qeh6mHt"}, + } + for _, tt := range tests { + t.Run(tt.label, func(t *testing.T) { + require.Equal(t, tt.expected, tt.id.String()) + }) + } +} + +func TestShortNodeIDMapMarshalling(t *testing.T) { + require := require.New(t) + + originalMap := map[ShortNodeID]int{ + {'e', 'v', 'a', ' ', 'l', 'a', 'b', 's'}: 1, + {'a', 'v', 'a', ' ', 'l', 'a', 'b', 's'}: 2, + } + mapJSON, err := json.Marshal(originalMap) + require.NoError(err) + + var unmarshalledMap map[ShortNodeID]int + require.NoError(json.Unmarshal(mapJSON, &unmarshalledMap)) + require.Equal(originalMap, unmarshalledMap) +} + +func TestShortNodeIDCompare(t *testing.T) { + tests := []struct { + a ShortNodeID + b ShortNodeID + expected int + }{ + { + a: ShortNodeID{1}, + b: ShortNodeID{0}, + expected: 1, + }, + { + a: ShortNodeID{1}, + b: ShortNodeID{1}, + expected: 0, + }, + { + a: ShortNodeID{1, 0}, + b: ShortNodeID{1, 2}, + expected: -1, + }, + } + for _, test := range tests { + t.Run(fmt.Sprintf("%s_%s_%d", test.a, test.b, test.expected), func(t *testing.T) { + require := require.New(t) + + require.Equal(test.expected, test.a.Compare(test.b)) + require.Equal(-test.expected, test.b.Compare(test.a)) + }) + } +} + +/* +func TestShortNodeIDToShortNodeIDConversion(t *testing.T) { + require := require.New(t) + + // EmptyNodeID --> EmptyShortNodeID + outputShort, err := ShortNodeIDFromNodeID(EmptyNodeID) + require.NoError(err) + require.Equal(EmptyShortNodeID, outputShort) + + // EmptyShortNodeID --> EmptyNodeID + output := NodeIDFromShortNodeID(EmptyShortNodeID) + require.Equal(EmptyNodeID, output) +} +*/ diff --git a/ids/test_generator.go b/ids/test_generator.go index 2df95ec0499f..8bd4ea03b9af 100644 --- a/ids/test_generator.go +++ b/ids/test_generator.go @@ -21,7 +21,12 @@ func GenerateTestShortID() ShortID { // GenerateTestNodeID returns a new ID that should only be used for testing func GenerateTestNodeID() NodeID { - return NodeID(GenerateTestShortID()) + return NodeID{ShortNodeID: ShortNodeID(GenerateTestShortID())} +} + +// GenerateTestShortNodeID returns a new ID that should only be used for testing +func GenerateTestShortNodeID() ShortNodeID { + return ShortNodeID(GenerateTestShortID()) } // BuildTestNodeID is an utility to build NodeID from bytes in UTs @@ -29,6 +34,14 @@ func GenerateTestNodeID() NodeID { // use ToNodeID, which performs proper length checking. func BuildTestNodeID(src []byte) NodeID { res := NodeID{} + copy(res.ShortNodeID[:], src) + return res +} + +// BuildTestNodeID is an utility to build ShortNodeID from bytes in UTs +// It must not be used in production code. +func BuildTestShortNodeID(src []byte) ShortNodeID { + res := ShortNodeID{} copy(res[:], src) return res } diff --git a/snow/engine/common/appsender/appsender_client.go b/snow/engine/common/appsender/appsender_client.go index 4477034f17cb..954164c5f379 100644 --- a/snow/engine/common/appsender/appsender_client.go +++ b/snow/engine/common/appsender/appsender_client.go @@ -57,7 +57,7 @@ func (c *Client) SendAppResponse(ctx context.Context, nodeID ids.NodeID, request func (c *Client) SendAppError(ctx context.Context, nodeID ids.NodeID, requestID uint32, errorCode int32, errorMessage string) error { _, err := c.client.SendAppError(ctx, &appsenderpb.SendAppErrorMsg{ - NodeId: nodeID[:], + NodeId: nodeID.Bytes(), RequestId: requestID, ErrorCode: errorCode, ErrorMessage: errorMessage, diff --git a/tests/fixture/tmpnet/genesis.go b/tests/fixture/tmpnet/genesis.go index aa308be6ee71..c091d1b2e1aa 100644 --- a/tests/fixture/tmpnet/genesis.go +++ b/tests/fixture/tmpnet/genesis.go @@ -177,12 +177,17 @@ func stakersForNodes(networkID uint32, nodes []*Node) ([]genesis.UnparsedStaker, // Configure provided nodes as initial stakers initialStakers := make([]genesis.UnparsedStaker, len(nodes)) for i, node := range nodes { + nodeID := node.NodeID + shortNodeID, err := ids.ShortNodeIDFromNodeID(node.NodeID) + if err != nil { + return nil, fmt.Errorf("failed to convert nodeID %v to shortNodeID: %w", nodeID, err) + } pop, err := node.GetProofOfPossession() if err != nil { return nil, fmt.Errorf("failed to derive proof of possession for node %s: %w", node.NodeID, err) } initialStakers[i] = genesis.UnparsedStaker{ - NodeID: node.NodeID, + NodeID: shortNodeID, RewardAddress: rewardAddr, DelegationFee: .01 * reward.PercentDenominator, Signer: pop, diff --git a/utils/ips/claimed_ip_port.go b/utils/ips/claimed_ip_port.go index 3721de9d624c..c7cf39a9d446 100644 --- a/utils/ips/claimed_ip_port.go +++ b/utils/ips/claimed_ip_port.go @@ -56,7 +56,7 @@ func NewClaimedIPPort( packer := wrappers.Packer{ Bytes: make([]byte, preimageLen), } - packer.PackFixedBytes(ip.NodeID[:]) + packer.PackFixedBytes(ip.NodeID.Bytes()) packer.PackLong(timestamp) ip.GossipID = hashing.ComputeHash256Array(packer.Bytes) return ip diff --git a/vms/platformvm/api/static_service.go b/vms/platformvm/api/static_service.go index 46f02bd46ba9..7b45d0ab451b 100644 --- a/vms/platformvm/api/static_service.go +++ b/vms/platformvm/api/static_service.go @@ -94,8 +94,16 @@ type Staker struct { StakeAmount *json.Uint64 `json:"stakeAmount,omitempty"` } -// GenesisValidator should to be used for genesis validators only. -type GenesisValidator Staker +// GenesisValidator is very similar to Staker, but it explicitly uses a ShortNodeID +// GenesisValidator should be used to generate genesis content only. +// APIs should use Staker struct only +type GenesisValidator struct { + TxID ids.ID `json:"txID"` + StartTime json.Uint64 `json:"startTime"` + EndTime json.Uint64 `json:"endTime"` + Weight json.Uint64 `json:"weight"` + NodeID ids.ShortNodeID `json:"nodeID"` +} // Owner is the repr. of a reward owner sent over APIs. type Owner struct { @@ -322,7 +330,7 @@ func (*StaticService) BuildGenesis(_ *http.Request, args *BuildGenesisArgs, repl BlockchainID: ids.Empty, }} validator = txs.Validator{ - NodeID: vdr.NodeID, + NodeID: vdr.NodeID.NodeID(), Start: uint64(args.Time), End: uint64(vdr.EndTime), Wght: weight, diff --git a/vms/platformvm/api/static_service_test.go b/vms/platformvm/api/static_service_test.go index a0e62fa9a31f..b9d589e47b5e 100644 --- a/vms/platformvm/api/static_service_test.go +++ b/vms/platformvm/api/static_service_test.go @@ -18,7 +18,7 @@ import ( func TestBuildGenesisInvalidUTXOBalance(t *testing.T) { require := require.New(t) - nodeID := ids.BuildTestNodeID([]byte{1, 2, 3}) + nodeID := ids.BuildTestShortNodeID([]byte{1, 2, 3}) addr, err := address.FormatBech32(constants.UnitTestHRP, nodeID.Bytes()) require.NoError(err) @@ -62,7 +62,7 @@ func TestBuildGenesisInvalidUTXOBalance(t *testing.T) { func TestBuildGenesisInvalidStakeWeight(t *testing.T) { require := require.New(t) - nodeID := ids.BuildTestNodeID([]byte{1, 2, 3}) + nodeID := ids.BuildTestShortNodeID([]byte{1, 2, 3}) addr, err := address.FormatBech32(constants.UnitTestHRP, nodeID.Bytes()) require.NoError(err) @@ -106,7 +106,7 @@ func TestBuildGenesisInvalidStakeWeight(t *testing.T) { func TestBuildGenesisInvalidEndtime(t *testing.T) { require := require.New(t) - nodeID := ids.BuildTestNodeID([]byte{1, 2, 3}) + nodeID := ids.BuildTestShortNodeID([]byte{1, 2, 3}) addr, err := address.FormatBech32(constants.UnitTestHRP, nodeID.Bytes()) require.NoError(err) @@ -151,7 +151,7 @@ func TestBuildGenesisInvalidEndtime(t *testing.T) { func TestBuildGenesisReturnsSortedValidators(t *testing.T) { require := require.New(t) - nodeID := ids.BuildTestNodeID([]byte{1}) + nodeID := ids.BuildTestShortNodeID([]byte{1}) addr, err := address.FormatBech32(constants.UnitTestHRP, nodeID.Bytes()) require.NoError(err) diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index 0ed61f930d01..da703b605502 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -78,13 +78,13 @@ var ( testSubnet1ControlKeys = preFundedKeys[0:3] // Node IDs of genesis validators. Initialized in init function - genesisNodeIDs []ids.NodeID + genesisNodeIDs []ids.ShortNodeID ) func init() { - genesisNodeIDs = make([]ids.NodeID, len(preFundedKeys)) + genesisNodeIDs = make([]ids.ShortNodeID, len(preFundedKeys)) for i := range preFundedKeys { - genesisNodeIDs[i] = ids.GenerateTestNodeID() + genesisNodeIDs[i] = ids.GenerateTestShortNodeID() } } diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index 22305de07ac7..1a8fa3d6e22e 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -81,13 +81,13 @@ var ( testSubnet1 *txs.Tx // Node IDs of genesis validators. Initialized in init function - genesisNodeIDs []ids.NodeID + genesisNodeIDs []ids.ShortNodeID ) func init() { - genesisNodeIDs = make([]ids.NodeID, len(preFundedKeys)) + genesisNodeIDs = make([]ids.ShortNodeID, len(preFundedKeys)) for i := range preFundedKeys { - genesisNodeIDs[i] = ids.GenerateTestNodeID() + genesisNodeIDs[i] = ids.GenerateTestShortNodeID() } } diff --git a/vms/platformvm/block/executor/proposal_block_test.go b/vms/platformvm/block/executor/proposal_block_test.go index 0dbcb74c11d5..c8281302b34e 100644 --- a/vms/platformvm/block/executor/proposal_block_test.go +++ b/vms/platformvm/block/executor/proposal_block_test.go @@ -723,7 +723,7 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: subnetValidatorNodeID, + NodeID: subnetValidatorNodeID.NodeID(), Start: uint64(subnetVdr1StartTime.Unix()), End: uint64(subnetVdr1EndTime.Unix()), Wght: 1, @@ -755,7 +755,7 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { utx, err = builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: subnetVdr2NodeID, + NodeID: subnetVdr2NodeID.NodeID(), Start: uint64(subnetVdr1EndTime.Add(time.Second).Unix()), End: uint64(subnetVdr1EndTime.Add(time.Second).Add(defaultMinStakingDuration).Unix()), Wght: 1, @@ -851,15 +851,15 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { blkStateMap := env.blkManager.(*manager).blkIDToState updatedState := blkStateMap[commitBlk.ID()].onAcceptState - _, err = updatedState.GetCurrentValidator(subnetID, subnetValidatorNodeID) + _, err = updatedState.GetCurrentValidator(subnetID, subnetValidatorNodeID.NodeID()) require.ErrorIs(err, database.ErrNotFound) // Check VM Validators are removed successfully require.NoError(propBlk.Accept(context.Background())) require.NoError(commitBlk.Accept(context.Background())) - _, ok := env.config.Validators.GetValidator(subnetID, subnetVdr2NodeID) + _, ok := env.config.Validators.GetValidator(subnetID, subnetVdr2NodeID.NodeID()) require.False(ok) - _, ok = env.config.Validators.GetValidator(subnetID, subnetValidatorNodeID) + _, ok = env.config.Validators.GetValidator(subnetID, subnetValidatorNodeID.NodeID()) require.False(ok) } @@ -883,7 +883,7 @@ func TestBanffProposalBlockTrackedSubnet(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: subnetValidatorNodeID, + NodeID: subnetValidatorNodeID.NodeID(), Start: uint64(subnetVdr1StartTime.Unix()), End: uint64(subnetVdr1EndTime.Unix()), Wght: 1, @@ -973,7 +973,7 @@ func TestBanffProposalBlockTrackedSubnet(t *testing.T) { require.NoError(propBlk.Accept(context.Background())) require.NoError(commitBlk.Accept(context.Background())) - _, ok := env.config.Validators.GetValidator(subnetID, subnetValidatorNodeID) + _, ok := env.config.Validators.GetValidator(subnetID, subnetValidatorNodeID.NodeID()) require.True(ok) }) } diff --git a/vms/platformvm/block/executor/standard_block_test.go b/vms/platformvm/block/executor/standard_block_test.go index 3dc1f999e789..e5a6e4dddaf6 100644 --- a/vms/platformvm/block/executor/standard_block_test.go +++ b/vms/platformvm/block/executor/standard_block_test.go @@ -608,7 +608,7 @@ func TestBanffStandardBlockRemoveSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: subnetValidatorNodeID, + NodeID: subnetValidatorNodeID.NodeID(), Start: uint64(subnetVdr1StartTime.Unix()), End: uint64(subnetVdr1EndTime.Unix()), Wght: 1, @@ -640,7 +640,7 @@ func TestBanffStandardBlockRemoveSubnetValidator(t *testing.T) { utx, err = builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: subnetVdr2NodeID, + NodeID: subnetVdr2NodeID.NodeID(), Start: uint64(subnetVdr1EndTime.Add(time.Second).Unix()), End: uint64(subnetVdr1EndTime.Add(time.Second).Add(defaultMinStakingDuration).Unix()), Wght: 1, @@ -684,14 +684,14 @@ func TestBanffStandardBlockRemoveSubnetValidator(t *testing.T) { blkStateMap := env.blkManager.(*manager).blkIDToState updatedState := blkStateMap[block.ID()].onAcceptState - _, err = updatedState.GetCurrentValidator(subnetID, subnetValidatorNodeID) + _, err = updatedState.GetCurrentValidator(subnetID, subnetValidatorNodeID.NodeID()) require.ErrorIs(err, database.ErrNotFound) // Check VM Validators are removed successfully require.NoError(block.Accept(context.Background())) - _, ok := env.config.Validators.GetValidator(subnetID, subnetVdr2NodeID) + _, ok := env.config.Validators.GetValidator(subnetID, subnetVdr2NodeID.NodeID()) require.False(ok) - _, ok = env.config.Validators.GetValidator(subnetID, subnetValidatorNodeID) + _, ok = env.config.Validators.GetValidator(subnetID, subnetValidatorNodeID.NodeID()) require.False(ok) } @@ -714,7 +714,7 @@ func TestBanffStandardBlockTrackedSubnet(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: subnetValidatorNodeID, + NodeID: subnetValidatorNodeID.NodeID(), Start: uint64(subnetVdr1StartTime.Unix()), End: uint64(subnetVdr1EndTime.Unix()), Wght: 1, @@ -755,7 +755,7 @@ func TestBanffStandardBlockTrackedSubnet(t *testing.T) { // update staker set require.NoError(block.Verify(context.Background())) require.NoError(block.Accept(context.Background())) - _, ok := env.config.Validators.GetValidator(subnetID, subnetValidatorNodeID) + _, ok := env.config.Validators.GetValidator(subnetID, subnetValidatorNodeID.NodeID()) require.True(ok) }) } diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index 3c89f712adf7..03190e7a8934 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -482,7 +482,7 @@ func TestGetStake(t *testing.T) { builder, signer := factory.NewWallet(keys[0]) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ - NodeID: delegatorNodeID, + NodeID: delegatorNodeID.NodeID(), Start: uint64(delegatorStartTime.Unix()), End: uint64(delegatorEndTime.Unix()), Wght: stakeAmount, @@ -611,7 +611,7 @@ func TestGetCurrentValidators(t *testing.T) { found := false for i := 0; i < len(response.Validators) && !found; i++ { gotVdr := response.Validators[i].(pchainapi.PermissionlessValidator) - if gotVdr.NodeID != vdr.NodeID { + if gotVdr.NodeID.Compare(vdr.NodeID.NodeID()) != 0 { continue } @@ -633,7 +633,7 @@ func TestGetCurrentValidators(t *testing.T) { builder, signer := factory.NewWallet(keys[0]) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ - NodeID: validatorNodeID, + NodeID: validatorNodeID.NodeID(), Start: uint64(delegatorStartTime.Unix()), End: uint64(delegatorEndTime.Unix()), Wght: stakeAmount, @@ -675,7 +675,7 @@ func TestGetCurrentValidators(t *testing.T) { found := false for i := 0; i < len(response.Validators) && !found; i++ { vdr := response.Validators[i].(pchainapi.PermissionlessValidator) - if vdr.NodeID != validatorNodeID { + if vdr.NodeID.Compare(validatorNodeID.NodeID()) != 0 { continue } found = true @@ -722,7 +722,7 @@ func TestGetCurrentValidators(t *testing.T) { for _, vdr := range response.Validators { castVdr := vdr.(pchainapi.PermissionlessValidator) - if castVdr.NodeID != validatorNodeID { + if castVdr.NodeID.Compare(validatorNodeID.NodeID()) != 0 { continue } require.Equal(uint64(100000), uint64(*castVdr.AccruedDelegateeReward)) diff --git a/vms/platformvm/state/disk_staker_diff_iterator.go b/vms/platformvm/state/disk_staker_diff_iterator.go index 1c6e88338724..a04828f8303e 100644 --- a/vms/platformvm/state/disk_staker_diff_iterator.go +++ b/vms/platformvm/state/disk_staker_diff_iterator.go @@ -57,7 +57,7 @@ func unmarshalDiffKey(key []byte) (ids.ID, uint64, ids.NodeID, error) { ) copy(subnetID[:], key) height := unpackIterableHeight(key[ids.IDLen:]) - copy(nodeID[:], key[diffKeyNodeIDOffset:]) + copy(nodeID.ShortNodeID[:], key[diffKeyNodeIDOffset:]) return subnetID, height, nodeID, nil } diff --git a/vms/platformvm/txs/executor/advance_time_test.go b/vms/platformvm/txs/executor/advance_time_test.go index e9e54ad8a3e6..dc0d1e798ab2 100644 --- a/vms/platformvm/txs/executor/advance_time_test.go +++ b/vms/platformvm/txs/executor/advance_time_test.go @@ -494,7 +494,7 @@ func TestAdvanceTimeTxRemoveSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: subnetValidatorNodeID, + NodeID: subnetValidatorNodeID.NodeID(), Start: uint64(subnetVdr1StartTime.Unix()), End: uint64(subnetVdr1EndTime.Unix()), Wght: 1, @@ -527,7 +527,7 @@ func TestAdvanceTimeTxRemoveSubnetValidator(t *testing.T) { utx, err = builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: subnetVdr2NodeID, + NodeID: subnetVdr2NodeID.NodeID(), Start: uint64(subnetVdr1EndTime.Add(time.Second).Unix()), End: uint64(subnetVdr1EndTime.Add(time.Second).Add(defaultMinStakingDuration).Unix()), Wght: 1, @@ -573,7 +573,7 @@ func TestAdvanceTimeTxRemoveSubnetValidator(t *testing.T) { } require.NoError(tx.Unsigned.Visit(&executor)) - _, err = executor.OnCommitState.GetCurrentValidator(subnetID, subnetValidatorNodeID) + _, err = executor.OnCommitState.GetCurrentValidator(subnetID, subnetValidatorNodeID.NodeID()) require.ErrorIs(err, database.ErrNotFound) // Check VM Validators are removed successfully @@ -581,9 +581,9 @@ func TestAdvanceTimeTxRemoveSubnetValidator(t *testing.T) { env.state.SetHeight(dummyHeight) require.NoError(env.state.Commit()) - _, ok := env.config.Validators.GetValidator(subnetID, subnetVdr2NodeID) + _, ok := env.config.Validators.GetValidator(subnetID, subnetVdr2NodeID.NodeID()) require.False(ok) - _, ok = env.config.Validators.GetValidator(subnetID, subnetValidatorNodeID) + _, ok = env.config.Validators.GetValidator(subnetID, subnetValidatorNodeID.NodeID()) require.False(ok) } @@ -610,7 +610,7 @@ func TestTrackedSubnet(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: subnetValidatorNodeID, + NodeID: subnetValidatorNodeID.NodeID(), Start: uint64(subnetVdr1StartTime.Unix()), End: uint64(subnetVdr1EndTime.Unix()), Wght: 1, @@ -658,7 +658,7 @@ func TestTrackedSubnet(t *testing.T) { env.state.SetHeight(dummyHeight) require.NoError(env.state.Commit()) - _, ok := env.config.Validators.GetValidator(subnetID, subnetValidatorNodeID) + _, ok := env.config.Validators.GetValidator(subnetID, subnetValidatorNodeID.NodeID()) require.True(ok) }) } diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index 2342f2270d43..c8912638d44e 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -73,13 +73,13 @@ var ( testSubnet1ControlKeys = preFundedKeys[0:3] // Node IDs of genesis validators. Initialized in init function - genesisNodeIDs []ids.NodeID + genesisNodeIDs []ids.ShortNodeID ) func init() { - genesisNodeIDs = make([]ids.NodeID, len(preFundedKeys)) + genesisNodeIDs = make([]ids.ShortNodeID, len(preFundedKeys)) for i := range preFundedKeys { - genesisNodeIDs[i] = ids.GenerateTestNodeID() + genesisNodeIDs[i] = ids.GenerateTestShortNodeID() } } diff --git a/vms/platformvm/txs/executor/proposal_tx_executor_test.go b/vms/platformvm/txs/executor/proposal_tx_executor_test.go index 0efbae5e65ba..3ecb5a6b00dc 100644 --- a/vms/platformvm/txs/executor/proposal_tx_executor_test.go +++ b/vms/platformvm/txs/executor/proposal_tx_executor_test.go @@ -131,7 +131,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { stakeAmount: env.config.MinDelegatorStake, startTime: uint64(defaultValidateStartTime.Unix()) + 1, endTime: uint64(defaultValidateEndTime.Unix()) + 1, - nodeID: nodeID, + nodeID: nodeID.NodeID(), feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, setup: nil, AP3Time: defaultGenesisTime, @@ -186,7 +186,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { stakeAmount: env.config.MinDelegatorStake, startTime: uint64(currentTimestamp.Unix()), endTime: uint64(defaultValidateEndTime.Unix()), - nodeID: nodeID, + nodeID: nodeID.NodeID(), feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, setup: nil, AP3Time: defaultGenesisTime, @@ -197,7 +197,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { stakeAmount: env.config.MinDelegatorStake, startTime: uint64(defaultValidateStartTime.Unix()) + 1, endTime: uint64(defaultValidateEndTime.Unix()), - nodeID: nodeID, + nodeID: nodeID.NodeID(), feeKeys: []*secp256k1.PrivateKey{preFundedKeys[1]}, setup: func(env *environment) { // Remove all UTXOs owned by keys[1] utxoIDs, err := env.state.UTXOIDs( @@ -301,7 +301,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID, + NodeID: nodeID.NodeID(), Start: uint64(defaultValidateStartTime.Unix()) + 1, End: uint64(defaultValidateEndTime.Unix()) + 1, Wght: defaultWeight, @@ -340,7 +340,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID, + NodeID: nodeID.NodeID(), Start: uint64(defaultValidateStartTime.Unix()) + 1, End: uint64(defaultValidateEndTime.Unix()), Wght: defaultWeight, @@ -566,7 +566,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID, + NodeID: nodeID.NodeID(), Start: uint64(newTimestamp.Unix()), End: uint64(newTimestamp.Add(defaultMinStakingDuration).Unix()), Wght: defaultWeight, @@ -605,7 +605,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { uSubnetTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID, + NodeID: nodeID.NodeID(), Start: uint64(defaultValidateStartTime.Unix()), End: uint64(defaultValidateEndTime.Unix()), Wght: defaultWeight, @@ -637,7 +637,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID, + NodeID: nodeID.NodeID(), Start: uint64(defaultValidateStartTime.Unix()) + 1, End: uint64(defaultValidateEndTime.Unix()), Wght: defaultWeight, @@ -677,7 +677,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID, + NodeID: nodeID.NodeID(), Start: uint64(defaultValidateStartTime.Unix()) + 1, End: uint64(defaultValidateStartTime.Add(defaultMinStakingDuration).Unix()) + 1, Wght: defaultWeight, @@ -720,7 +720,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID, + NodeID: nodeID.NodeID(), Start: uint64(defaultValidateStartTime.Unix()) + 1, End: uint64(defaultValidateStartTime.Add(defaultMinStakingDuration).Unix()) + 1, Wght: defaultWeight, @@ -762,7 +762,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID, + NodeID: nodeID.NodeID(), Start: uint64(defaultValidateStartTime.Unix()) + 1, End: uint64(defaultValidateStartTime.Add(defaultMinStakingDuration).Unix()) + 1, Wght: defaultWeight, @@ -861,7 +861,7 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { builder, signer := env.factory.NewWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ - NodeID: nodeID, + NodeID: nodeID.NodeID(), Start: uint64(defaultValidateStartTime.Unix()) + 1, End: uint64(defaultValidateEndTime.Unix()), Wght: env.config.MinValidatorStake, diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index d2a0010f87c5..475128a432db 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -215,7 +215,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { stakeAmount: env.config.MinDelegatorStake, startTime: defaultValidateStartTime.Add(time.Second), endTime: defaultValidateEndTime.Add(time.Second), - nodeID: nodeID, + nodeID: nodeID.NodeID(), feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, setup: nil, AP3Time: defaultGenesisTime, @@ -270,7 +270,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { stakeAmount: env.config.MinDelegatorStake, // weight startTime: currentTimestamp, // start time endTime: defaultValidateEndTime, // end time - nodeID: nodeID, // node ID + nodeID: nodeID.NodeID(), // node ID feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, // tx fee payer setup: nil, AP3Time: defaultGenesisTime, @@ -281,7 +281,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { stakeAmount: env.config.MinDelegatorStake, // weight startTime: defaultValidateStartTime.Add(time.Second), // start time endTime: defaultValidateEndTime, // end time - nodeID: nodeID, // node ID + nodeID: nodeID.NodeID(), // node ID feeKeys: []*secp256k1.PrivateKey{preFundedKeys[1]}, // tx fee payer setup: func(env *environment) { // Remove all UTXOs owned by keys[1] utxoIDs, err := env.state.UTXOIDs( @@ -385,7 +385,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID, + NodeID: nodeID.NodeID(), Start: uint64(startTime.Unix()), End: uint64(defaultValidateEndTime.Unix()) + 1, Wght: defaultWeight, @@ -420,7 +420,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID, + NodeID: nodeID.NodeID(), Start: uint64(defaultValidateStartTime.Unix() + 1), End: uint64(defaultValidateEndTime.Unix()), Wght: defaultWeight, @@ -626,7 +626,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID, + NodeID: nodeID.NodeID(), Start: uint64(newTimestamp.Unix()), End: uint64(newTimestamp.Add(defaultMinStakingDuration).Unix()), Wght: defaultWeight, @@ -661,7 +661,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { uSubnetTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID, + NodeID: nodeID.NodeID(), Start: uint64(defaultValidateStartTime.Unix()), End: uint64(defaultValidateEndTime.Unix()), Wght: defaultWeight, @@ -694,7 +694,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID, + NodeID: nodeID.NodeID(), Start: uint64(startTime.Unix()), End: uint64(defaultValidateEndTime.Unix()), Wght: defaultWeight, @@ -731,7 +731,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID, + NodeID: nodeID.NodeID(), Start: uint64(startTime.Unix()), End: uint64(startTime.Add(defaultMinStakingDuration).Unix()) + 1, Wght: defaultWeight, @@ -771,7 +771,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID, + NodeID: nodeID.NodeID(), Start: uint64(startTime.Unix()), End: uint64(startTime.Add(defaultMinStakingDuration).Unix()), Wght: defaultWeight, @@ -811,7 +811,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID, + NodeID: nodeID.NodeID(), Start: uint64(startTime.Unix()), End: uint64(startTime.Add(defaultMinStakingDuration).Unix()), Wght: defaultWeight, @@ -850,7 +850,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID, + NodeID: nodeID.NodeID(), Start: uint64(startTime.Unix()) + 1, End: uint64(startTime.Add(defaultMinStakingDuration).Unix()) + 1, Wght: defaultWeight, @@ -903,7 +903,7 @@ func TestEtnaStandardTxExecutorAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID, + NodeID: nodeID.NodeID(), Start: uint64(defaultValidateStartTime.Unix() + 1), End: uint64(defaultValidateEndTime.Unix()), Wght: defaultWeight, diff --git a/vms/platformvm/validators/manager_benchmark_test.go b/vms/platformvm/validators/manager_benchmark_test.go index 8215a54475a4..ed87bbcad62a 100644 --- a/vms/platformvm/validators/manager_benchmark_test.go +++ b/vms/platformvm/validators/manager_benchmark_test.go @@ -67,7 +67,7 @@ func BenchmarkGetValidatorSet(b *testing.B) { GenesisValidator: api.GenesisValidator{ StartTime: json.Uint64(genesisTime.Unix()), EndTime: json.Uint64(genesisEndTime.Unix()), - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), }, RewardOwner: &api.Owner{ Threshold: 1, diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index 3146a8372518..3880af0b6ac8 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -1114,11 +1114,11 @@ func TestValidatorSetAtCacheOverwriteRegression(t *testing.T) { require.Equal(uint64(1), currentHeight) expectedValidators1 := map[ids.NodeID]uint64{ - genesisNodeIDs[0]: defaultWeight, - genesisNodeIDs[1]: defaultWeight, - genesisNodeIDs[2]: defaultWeight, - genesisNodeIDs[3]: defaultWeight, - genesisNodeIDs[4]: defaultWeight, + genesisNodeIDs[0].NodeID(): defaultWeight, + genesisNodeIDs[1].NodeID(): defaultWeight, + genesisNodeIDs[2].NodeID(): defaultWeight, + genesisNodeIDs[3].NodeID(): defaultWeight, + genesisNodeIDs[4].NodeID(): defaultWeight, } validators, err := vm.GetValidatorSet(context.Background(), 1, constants.PrimaryNetworkID) require.NoError(err) @@ -1218,12 +1218,12 @@ func TestValidatorSetAtCacheOverwriteRegression(t *testing.T) { } expectedValidators2 := map[ids.NodeID]uint64{ - genesisNodeIDs[0]: defaultWeight, - genesisNodeIDs[1]: defaultWeight, - genesisNodeIDs[2]: defaultWeight, - genesisNodeIDs[3]: defaultWeight, - genesisNodeIDs[4]: defaultWeight, - extraNodeID: vm.MaxValidatorStake, + genesisNodeIDs[0].NodeID(): defaultWeight, + genesisNodeIDs[1].NodeID(): defaultWeight, + genesisNodeIDs[2].NodeID(): defaultWeight, + genesisNodeIDs[3].NodeID(): defaultWeight, + genesisNodeIDs[4].NodeID(): defaultWeight, + extraNodeID: vm.MaxValidatorStake, } validators, err = vm.GetValidatorSet(context.Background(), 3, constants.PrimaryNetworkID) require.NoError(err) diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 4175c0346c70..7e86dcf138c8 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -106,7 +106,7 @@ var ( keys = secp256k1.TestKeys() // Node IDs of genesis validators. Initialized in init function - genesisNodeIDs []ids.NodeID + genesisNodeIDs []ids.ShortNodeID defaultMinDelegatorStake = 1 * units.MilliAvax defaultMinValidatorStake = 5 * defaultMinDelegatorStake defaultMaxValidatorStake = 100 * defaultMinValidatorStake @@ -144,7 +144,7 @@ func init() { // TODO: use ids.GenerateTestNodeID() instead of ids.BuildTestNodeID // Can be done when TestGetState is refactored nodeBytes := key.PublicKey().Address() - nodeID := ids.BuildTestNodeID(nodeBytes[:]) + nodeID := ids.BuildTestShortNodeID(nodeBytes[:]) genesisNodeIDs = append(genesisNodeIDs, nodeID) } @@ -372,7 +372,7 @@ func TestGenesis(t *testing.T) { require.Len(genesisState.Validators, vm.Validators.Count(constants.PrimaryNetworkID)) for _, nodeID := range genesisNodeIDs { - _, ok := vm.Validators.GetValidator(constants.PrimaryNetworkID, nodeID) + _, ok := vm.Validators.GetValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.True(ok) } @@ -574,7 +574,7 @@ func TestAddValidatorInvalidNotReissued(t *testing.T) { utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: repeatNodeID, + NodeID: repeatNodeID.NodeID(), Start: uint64(startTime.Unix()), End: uint64(endTime.Unix()), Wght: vm.MinValidatorStake, @@ -624,7 +624,7 @@ func TestAddSubnetValidatorAccept(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID, + NodeID: nodeID.NodeID(), Start: uint64(startTime.Unix()), End: uint64(endTime.Unix()), Wght: defaultWeight, @@ -652,7 +652,7 @@ func TestAddSubnetValidatorAccept(t *testing.T) { require.Equal(status.Committed, txStatus) // Verify that new validator is in current validator set - _, err = vm.state.GetCurrentValidator(testSubnet1.ID(), nodeID) + _, err = vm.state.GetCurrentValidator(testSubnet1.ID(), nodeID.NodeID()) require.NoError(err) } @@ -676,7 +676,7 @@ func TestAddSubnetValidatorReject(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID, + NodeID: nodeID.NodeID(), Start: uint64(startTime.Unix()), End: uint64(endTime.Unix()), Wght: defaultWeight, @@ -703,7 +703,7 @@ func TestAddSubnetValidatorReject(t *testing.T) { require.ErrorIs(err, database.ErrNotFound) // Verify that new validator NOT in validator set - _, err = vm.state.GetCurrentValidator(testSubnet1.ID(), nodeID) + _, err = vm.state.GetCurrentValidator(testSubnet1.ID(), nodeID.NodeID()) require.ErrorIs(err, database.ErrNotFound) } @@ -960,7 +960,7 @@ func TestCreateSubnet(t *testing.T) { uAddValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID, + NodeID: nodeID.NodeID(), Start: uint64(startTime.Unix()), End: uint64(endTime.Unix()), Wght: defaultWeight, @@ -988,10 +988,10 @@ func TestCreateSubnet(t *testing.T) { require.NoError(err) require.Equal(status.Committed, txStatus) - _, err = vm.state.GetPendingValidator(subnetID, nodeID) + _, err = vm.state.GetPendingValidator(subnetID, nodeID.NodeID()) require.ErrorIs(err, database.ErrNotFound) - _, err = vm.state.GetCurrentValidator(subnetID, nodeID) + _, err = vm.state.GetCurrentValidator(subnetID, nodeID.NodeID()) require.NoError(err) // fast forward clock to time validator should stop validating @@ -1001,10 +1001,10 @@ func TestCreateSubnet(t *testing.T) { require.NoError(blk.Verify(context.Background())) require.NoError(blk.Accept(context.Background())) // remove validator from current validator set - _, err = vm.state.GetPendingValidator(subnetID, nodeID) + _, err = vm.state.GetPendingValidator(subnetID, nodeID.NodeID()) require.ErrorIs(err, database.ErrNotFound) - _, err = vm.state.GetCurrentValidator(subnetID, nodeID) + _, err = vm.state.GetCurrentValidator(subnetID, nodeID.NodeID()) require.ErrorIs(err, database.ErrNotFound) } @@ -1782,7 +1782,7 @@ func TestMaxStakeAmount(t *testing.T) { for _, test := range tests { t.Run(test.description, func(t *testing.T) { require := require.New(t) - staker, err := txexecutor.GetValidator(vm.state, constants.PrimaryNetworkID, nodeID) + staker, err := txexecutor.GetValidator(vm.state, constants.PrimaryNetworkID, nodeID.NodeID()) require.NoError(err) amount, err := txexecutor.GetMaxWeight(vm.state, staker, test.startTime, test.endTime) diff --git a/wallet/subnet/primary/example_test.go b/wallet/subnet/primary/example_test.go index 6c2390e00be4..bfb1505438cf 100644 --- a/wallet/subnet/primary/example_test.go +++ b/wallet/subnet/primary/example_test.go @@ -146,7 +146,7 @@ func ExampleWallet() { addSubnetValidatorTx, err := pWallet.IssueAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: genesis.LocalConfig.InitialStakers[0].NodeID, + NodeID: genesis.LocalConfig.InitialStakers[0].NodeID.NodeID(), Start: uint64(startTime.Unix()), End: uint64(startTime.Add(5 * time.Second).Unix()), Wght: 25 * units.MegaAvax, @@ -170,7 +170,7 @@ func ExampleWallet() { addSubnetDelegatorTx, err := pWallet.IssueAddPermissionlessDelegatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: genesis.LocalConfig.InitialStakers[0].NodeID, + NodeID: genesis.LocalConfig.InitialStakers[0].NodeID.NodeID(), Start: uint64(startTime.Unix()), End: uint64(startTime.Add(5 * time.Second).Unix()), Wght: 25 * units.MegaAvax, From 05e180d92f41b3d24d0e25c57624c65578f8b155 Mon Sep 17 00:00:00 2001 From: tsachiherman <24438559+tsachiherman@users.noreply.github.com> Date: Wed, 21 Aug 2024 16:02:58 -0400 Subject: [PATCH 02/17] update --- ids/node_id.go | 2 +- vms/platformvm/api/static_service_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ids/node_id.go b/ids/node_id.go index 7695d642742c..85047a043b21 100644 --- a/ids/node_id.go +++ b/ids/node_id.go @@ -21,7 +21,7 @@ var ( ) type NodeID struct { - ShortNodeID + ShortNodeID `serialize:"true"` } // ToNodeID attempt to convert a byte slice into a node id diff --git a/vms/platformvm/api/static_service_test.go b/vms/platformvm/api/static_service_test.go index b9d589e47b5e..041a8c3dca15 100644 --- a/vms/platformvm/api/static_service_test.go +++ b/vms/platformvm/api/static_service_test.go @@ -242,9 +242,9 @@ func TestUTXOCompare(t *testing.T) { smallerAddr = ids.ShortID{} largerAddr = ids.ShortID{1} ) - smallerAddrStr, err := address.FormatBech32("avax", smallerAddr[:]) + smallerAddrStr, err := address.FormatBech32("avax", smallerAddr.Bytes()) require.NoError(t, err) - largerAddrStr, err := address.FormatBech32("avax", largerAddr[:]) + largerAddrStr, err := address.FormatBech32("avax", largerAddr.Bytes()) require.NoError(t, err) type test struct { From f87604df62941fed63468d5c4512aa2ea3008cb8 Mon Sep 17 00:00:00 2001 From: tsachiherman <24438559+tsachiherman@users.noreply.github.com> Date: Wed, 21 Aug 2024 16:17:32 -0400 Subject: [PATCH 03/17] update --- ids/short_node_id.go | 2 +- ids/short_node_id_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ids/short_node_id.go b/ids/short_node_id.go index 00e26f4855e5..ef7b8b7e804a 100644 --- a/ids/short_node_id.go +++ b/ids/short_node_id.go @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/ids/short_node_id_test.go b/ids/short_node_id_test.go index d7708d3491ba..5a8768f9a5d1 100644 --- a/ids/short_node_id_test.go +++ b/ids/short_node_id_test.go @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids From fbe8fc79f7ab60f6e0f8ea35785775ac88056b06 Mon Sep 17 00:00:00 2001 From: tsachiherman <24438559+tsachiherman@users.noreply.github.com> Date: Thu, 22 Aug 2024 10:56:28 -0400 Subject: [PATCH 04/17] update --- ids/test_generator.go | 2 +- .../state/disk_staker_diff_iterator.go | 2 +- vms/platformvm/vm_regression_test.go | 46 +++++++++---------- vms/platformvm/vm_test.go | 4 +- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/ids/test_generator.go b/ids/test_generator.go index 8bd4ea03b9af..a43a0ee04df6 100644 --- a/ids/test_generator.go +++ b/ids/test_generator.go @@ -34,7 +34,7 @@ func GenerateTestShortNodeID() ShortNodeID { // use ToNodeID, which performs proper length checking. func BuildTestNodeID(src []byte) NodeID { res := NodeID{} - copy(res.ShortNodeID[:], src) + copy(res.ShortNodeID.Bytes(), src) return res } diff --git a/vms/platformvm/state/disk_staker_diff_iterator.go b/vms/platformvm/state/disk_staker_diff_iterator.go index a04828f8303e..df4b2e088353 100644 --- a/vms/platformvm/state/disk_staker_diff_iterator.go +++ b/vms/platformvm/state/disk_staker_diff_iterator.go @@ -57,7 +57,7 @@ func unmarshalDiffKey(key []byte) (ids.ID, uint64, ids.NodeID, error) { ) copy(subnetID[:], key) height := unpackIterableHeight(key[ids.IDLen:]) - copy(nodeID.ShortNodeID[:], key[diffKeyNodeIDOffset:]) + copy(nodeID.ShortNodeID.Bytes(), key[diffKeyNodeIDOffset:]) return subnetID, height, nodeID, nil } diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index 55fd7dafd670..12b3596ad3de 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -1101,29 +1101,29 @@ func TestValidatorSetAtCacheOverwriteRegression(t *testing.T) { require.NoError(err) require.Equal(uint64(1), currentHeight) - expectedValidators1 := map[ids.NodeID]uint64{ - genesisNodeIDs[0].NodeID(): defaultWeight, - genesisNodeIDs[1].NodeID(): defaultWeight, - genesisNodeIDs[2].NodeID(): defaultWeight, - genesisNodeIDs[3].NodeID(): defaultWeight, - genesisNodeIDs[4].NodeID(): defaultWeight, + expectedValidators1 := map[ids.ShortNodeID]uint64{ + genesisNodeIDs[0]: defaultWeight, + genesisNodeIDs[1]: defaultWeight, + genesisNodeIDs[2]: defaultWeight, + genesisNodeIDs[3]: defaultWeight, + genesisNodeIDs[4]: defaultWeight, } validators, err := vm.GetValidatorSet(context.Background(), 1, constants.PrimaryNetworkID) require.NoError(err) - for nodeID, weight := range expectedValidators1 { - require.Equal(weight, validators[nodeID].Weight) + for shortNodeID, weight := range expectedValidators1 { + require.Equal(weight, validators[shortNodeID.NodeID()].Weight) } newValidatorStartTime0 := vm.clock.Time().Add(executor.SyncBound).Add(1 * time.Second) newValidatorEndTime0 := newValidatorStartTime0.Add(defaultMaxStakingDuration) - extraNodeID := ids.GenerateTestNodeID() + extraShortNodeID := ids.GenerateTestShortNodeID() // Create the tx to add the first new validator builder, txSigner := factory.NewWallet(keys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ - NodeID: extraNodeID, + NodeID: extraShortNodeID.NodeID(), Start: uint64(newValidatorStartTime0.Unix()), End: uint64(newValidatorEndTime0.Unix()), Wght: vm.MaxValidatorStake, @@ -1164,8 +1164,8 @@ func TestValidatorSetAtCacheOverwriteRegression(t *testing.T) { for i := uint64(1); i <= 2; i++ { validators, err = vm.GetValidatorSet(context.Background(), i, constants.PrimaryNetworkID) require.NoError(err) - for nodeID, weight := range expectedValidators1 { - require.Equal(weight, validators[nodeID].Weight) + for shortNodeID, weight := range expectedValidators1 { + require.Equal(weight, validators[shortNodeID.NodeID()].Weight) } } @@ -1200,23 +1200,23 @@ func TestValidatorSetAtCacheOverwriteRegression(t *testing.T) { for i := uint64(1); i <= 2; i++ { validators, err = vm.GetValidatorSet(context.Background(), i, constants.PrimaryNetworkID) require.NoError(err) - for nodeID, weight := range expectedValidators1 { - require.Equal(weight, validators[nodeID].Weight) + for shortNodeID, weight := range expectedValidators1 { + require.Equal(weight, validators[shortNodeID.NodeID()].Weight) } } - expectedValidators2 := map[ids.NodeID]uint64{ - genesisNodeIDs[0].NodeID(): defaultWeight, - genesisNodeIDs[1].NodeID(): defaultWeight, - genesisNodeIDs[2].NodeID(): defaultWeight, - genesisNodeIDs[3].NodeID(): defaultWeight, - genesisNodeIDs[4].NodeID(): defaultWeight, - extraNodeID: vm.MaxValidatorStake, + expectedValidators2 := map[ids.ShortNodeID]uint64{ + genesisNodeIDs[0]: defaultWeight, + genesisNodeIDs[1]: defaultWeight, + genesisNodeIDs[2]: defaultWeight, + genesisNodeIDs[3]: defaultWeight, + genesisNodeIDs[4]: defaultWeight, + extraShortNodeID: vm.MaxValidatorStake, } validators, err = vm.GetValidatorSet(context.Background(), 3, constants.PrimaryNetworkID) require.NoError(err) - for nodeID, weight := range expectedValidators2 { - require.Equal(weight, validators[nodeID].Weight) + for shortNodeID, weight := range expectedValidators2 { + require.Equal(weight, validators[shortNodeID.NodeID()].Weight) } } diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index ecb143917b0c..ff7cf891e760 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -371,8 +371,8 @@ func TestGenesis(t *testing.T) { // Ensure current validator set of primary network is correct require.Len(genesisState.Validators, vm.Validators.Count(constants.PrimaryNetworkID)) - for _, nodeID := range genesisNodeIDs { - _, ok := vm.Validators.GetValidator(constants.PrimaryNetworkID, nodeID.NodeID()) + for _, shortNodeID := range genesisNodeIDs { + _, ok := vm.Validators.GetValidator(constants.PrimaryNetworkID, shortNodeID.NodeID()) require.True(ok) } From dab14e03cb4f737f9738971e37d1b50952a91375 Mon Sep 17 00:00:00 2001 From: tsachiherman <24438559+tsachiherman@users.noreply.github.com> Date: Thu, 22 Aug 2024 12:18:03 -0400 Subject: [PATCH 05/17] update --- ids/node_id.go | 6 ---- .../common/appsender/appsender_server.go | 16 +++++------ .../gvalidators/validator_state_client.go | 3 +- tests/e2e/p/workflow.go | 4 +-- vms/rpcchainvm/vm_server.go | 28 +++++++++---------- 5 files changed, 26 insertions(+), 31 deletions(-) diff --git a/ids/node_id.go b/ids/node_id.go index 85047a043b21..f1ff41dd3309 100644 --- a/ids/node_id.go +++ b/ids/node_id.go @@ -24,12 +24,6 @@ type NodeID struct { ShortNodeID `serialize:"true"` } -// ToNodeID attempt to convert a byte slice into a node id -func ToNodeID(bytes []byte) (NodeID, error) { - nodeID, err := ToShortID(bytes) - return NodeID{ShortNodeID: ShortNodeID(nodeID)}, err -} - func (id NodeID) Compare(other NodeID) int { return id.ShortNodeID.Compare(other.ShortNodeID) } diff --git a/snow/engine/common/appsender/appsender_server.go b/snow/engine/common/appsender/appsender_server.go index 73092d3e0860..aec3f2d6d878 100644 --- a/snow/engine/common/appsender/appsender_server.go +++ b/snow/engine/common/appsender/appsender_server.go @@ -30,43 +30,43 @@ func NewServer(appSender common.AppSender) *Server { func (s *Server) SendAppRequest(ctx context.Context, req *appsenderpb.SendAppRequestMsg) (*emptypb.Empty, error) { nodeIDs := set.NewSet[ids.NodeID](len(req.NodeIds)) for _, nodeIDBytes := range req.NodeIds { - nodeID, err := ids.ToNodeID(nodeIDBytes) + shortNodeID, err := ids.ToShortNodeID(nodeIDBytes) if err != nil { return nil, err } - nodeIDs.Add(nodeID) + nodeIDs.Add(shortNodeID.NodeID()) } err := s.appSender.SendAppRequest(ctx, nodeIDs, req.RequestId, req.Request) return &emptypb.Empty{}, err } func (s *Server) SendAppResponse(ctx context.Context, req *appsenderpb.SendAppResponseMsg) (*emptypb.Empty, error) { - nodeID, err := ids.ToNodeID(req.NodeId) + shortNodeID, err := ids.ToShortNodeID(req.NodeId) if err != nil { return nil, err } - err = s.appSender.SendAppResponse(ctx, nodeID, req.RequestId, req.Response) + err = s.appSender.SendAppResponse(ctx, shortNodeID.NodeID(), req.RequestId, req.Response) return &emptypb.Empty{}, err } func (s *Server) SendAppError(ctx context.Context, req *appsenderpb.SendAppErrorMsg) (*emptypb.Empty, error) { - nodeID, err := ids.ToNodeID(req.NodeId) + shortNodeID, err := ids.ToShortNodeID(req.NodeId) if err != nil { return nil, err } - err = s.appSender.SendAppError(ctx, nodeID, req.RequestId, req.ErrorCode, req.ErrorMessage) + err = s.appSender.SendAppError(ctx, shortNodeID.NodeID(), req.RequestId, req.ErrorCode, req.ErrorMessage) return &emptypb.Empty{}, err } func (s *Server) SendAppGossip(ctx context.Context, req *appsenderpb.SendAppGossipMsg) (*emptypb.Empty, error) { nodeIDs := set.NewSet[ids.NodeID](len(req.NodeIds)) for _, nodeIDBytes := range req.NodeIds { - nodeID, err := ids.ToNodeID(nodeIDBytes) + shortNodeID, err := ids.ToShortNodeID(nodeIDBytes) if err != nil { return nil, err } - nodeIDs.Add(nodeID) + nodeIDs.Add(shortNodeID.NodeID()) } err := s.appSender.SendAppGossip( ctx, diff --git a/snow/validators/gvalidators/validator_state_client.go b/snow/validators/gvalidators/validator_state_client.go index ae09b749d3ca..3efe5d9f55ac 100644 --- a/snow/validators/gvalidators/validator_state_client.go +++ b/snow/validators/gvalidators/validator_state_client.go @@ -70,10 +70,11 @@ func (c *Client) GetValidatorSet( vdrs := make(map[ids.NodeID]*validators.GetValidatorOutput, len(resp.Validators)) for _, validator := range resp.Validators { - nodeID, err := ids.ToNodeID(validator.NodeId) + shortNodeID, err := ids.ToShortNodeID(validator.NodeId) if err != nil { return nil, err } + nodeID := shortNodeID.NodeID() var publicKey *bls.PublicKey if len(validator.PublicKey) > 0 { // This is a performance optimization to avoid the cost of diff --git a/tests/e2e/p/workflow.go b/tests/e2e/p/workflow.go index 333b0c013705..25f6dda5ef31 100644 --- a/tests/e2e/p/workflow.go +++ b/tests/e2e/p/workflow.go @@ -86,12 +86,12 @@ var _ = e2e.DescribePChain("[Workflow]", func() { // Use a random node ID to ensure that repeated test runs will succeed // against a network that persists across runs. - validatorID, err := ids.ToNodeID(utils.RandomBytes(ids.NodeIDLen)) + validatorID, err := ids.ToShortNodeID(utils.RandomBytes(ids.NodeIDLen)) require.NoError(err) vdr := &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: validatorID, + NodeID: validatorID.NodeID(), End: uint64(time.Now().Add(72 * time.Hour).Unix()), Wght: minValStake, }, diff --git a/vms/rpcchainvm/vm_server.go b/vms/rpcchainvm/vm_server.go index a5a9266a2434..8905974c1603 100644 --- a/vms/rpcchainvm/vm_server.go +++ b/vms/rpcchainvm/vm_server.go @@ -106,7 +106,7 @@ func (vm *VMServer) Initialize(ctx context.Context, req *vmpb.InitializeRequest) if err != nil { return nil, err } - nodeID, err := ids.ToNodeID(req.NodeId) + shortNodeID, err := ids.ToShortNodeID(req.NodeId) if err != nil { return nil, err } @@ -241,7 +241,7 @@ func (vm *VMServer) Initialize(ctx context.Context, req *vmpb.InitializeRequest) NetworkID: req.NetworkId, SubnetID: subnetID, ChainID: chainID, - NodeID: nodeID, + NodeID: shortNodeID.NodeID(), PublicKey: publicKey, NetworkUpgrades: networkUpgrades, @@ -364,7 +364,7 @@ func (vm *VMServer) CreateHandlers(ctx context.Context, _ *emptypb.Empty) (*vmpb } func (vm *VMServer) Connected(ctx context.Context, req *vmpb.ConnectedRequest) (*emptypb.Empty, error) { - nodeID, err := ids.ToNodeID(req.NodeId) + shortNodeID, err := ids.ToShortNodeID(req.NodeId) if err != nil { return nil, err } @@ -375,15 +375,15 @@ func (vm *VMServer) Connected(ctx context.Context, req *vmpb.ConnectedRequest) ( Minor: int(req.Minor), Patch: int(req.Patch), } - return &emptypb.Empty{}, vm.vm.Connected(ctx, nodeID, peerVersion) + return &emptypb.Empty{}, vm.vm.Connected(ctx, shortNodeID.NodeID(), peerVersion) } func (vm *VMServer) Disconnected(ctx context.Context, req *vmpb.DisconnectedRequest) (*emptypb.Empty, error) { - nodeID, err := ids.ToNodeID(req.NodeId) + shortNodeID, err := ids.ToShortNodeID(req.NodeId) if err != nil { return nil, err } - return &emptypb.Empty{}, vm.vm.Disconnected(ctx, nodeID) + return &emptypb.Empty{}, vm.vm.Disconnected(ctx, shortNodeID.NodeID()) } // If the underlying VM doesn't actually implement this method, its [BuildBlock] @@ -519,7 +519,7 @@ func (vm *VMServer) Version(ctx context.Context, _ *emptypb.Empty) (*vmpb.Versio } func (vm *VMServer) AppRequest(ctx context.Context, req *vmpb.AppRequestMsg) (*emptypb.Empty, error) { - nodeID, err := ids.ToNodeID(req.NodeId) + shortNodeID, err := ids.ToShortNodeID(req.NodeId) if err != nil { return nil, err } @@ -527,11 +527,11 @@ func (vm *VMServer) AppRequest(ctx context.Context, req *vmpb.AppRequestMsg) (*e if err != nil { return nil, err } - return &emptypb.Empty{}, vm.vm.AppRequest(ctx, nodeID, req.RequestId, deadline, req.Request) + return &emptypb.Empty{}, vm.vm.AppRequest(ctx, shortNodeID.NodeID(), req.RequestId, deadline, req.Request) } func (vm *VMServer) AppRequestFailed(ctx context.Context, req *vmpb.AppRequestFailedMsg) (*emptypb.Empty, error) { - nodeID, err := ids.ToNodeID(req.NodeId) + shortNodeID, err := ids.ToShortNodeID(req.NodeId) if err != nil { return nil, err } @@ -540,23 +540,23 @@ func (vm *VMServer) AppRequestFailed(ctx context.Context, req *vmpb.AppRequestFa Code: req.ErrorCode, Message: req.ErrorMessage, } - return &emptypb.Empty{}, vm.vm.AppRequestFailed(ctx, nodeID, req.RequestId, appErr) + return &emptypb.Empty{}, vm.vm.AppRequestFailed(ctx, shortNodeID.NodeID(), req.RequestId, appErr) } func (vm *VMServer) AppResponse(ctx context.Context, req *vmpb.AppResponseMsg) (*emptypb.Empty, error) { - nodeID, err := ids.ToNodeID(req.NodeId) + shortNodeID, err := ids.ToShortNodeID(req.NodeId) if err != nil { return nil, err } - return &emptypb.Empty{}, vm.vm.AppResponse(ctx, nodeID, req.RequestId, req.Response) + return &emptypb.Empty{}, vm.vm.AppResponse(ctx, shortNodeID.NodeID(), req.RequestId, req.Response) } func (vm *VMServer) AppGossip(ctx context.Context, req *vmpb.AppGossipMsg) (*emptypb.Empty, error) { - nodeID, err := ids.ToNodeID(req.NodeId) + shortNodeID, err := ids.ToShortNodeID(req.NodeId) if err != nil { return nil, err } - return &emptypb.Empty{}, vm.vm.AppGossip(ctx, nodeID, req.Msg) + return &emptypb.Empty{}, vm.vm.AppGossip(ctx, shortNodeID.NodeID(), req.Msg) } func (vm *VMServer) Gather(context.Context, *emptypb.Empty) (*vmpb.GatherResponse, error) { From b44ca0de484d7503ef7623d349cf23345bc282c1 Mon Sep 17 00:00:00 2001 From: tsachiherman <24438559+tsachiherman@users.noreply.github.com> Date: Thu, 22 Aug 2024 13:10:32 -0400 Subject: [PATCH 06/17] fix unit tests --- ids/test_generator.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ids/test_generator.go b/ids/test_generator.go index a43a0ee04df6..973c74ee9669 100644 --- a/ids/test_generator.go +++ b/ids/test_generator.go @@ -33,9 +33,9 @@ func GenerateTestShortNodeID() ShortNodeID { // It must not be used in production code. In production code we should // use ToNodeID, which performs proper length checking. func BuildTestNodeID(src []byte) NodeID { - res := NodeID{} - copy(res.ShortNodeID.Bytes(), src) - return res + res := ShortNodeID{} + copy(res[:], src) + return res.NodeID() } // BuildTestNodeID is an utility to build ShortNodeID from bytes in UTs From 4f1ac5afd6456c367b2e39e43af0cf49e14fdf8a Mon Sep 17 00:00:00 2001 From: tsachiherman <24438559+tsachiherman@users.noreply.github.com> Date: Thu, 22 Aug 2024 13:18:45 -0400 Subject: [PATCH 07/17] update --- .../state/disk_staker_diff_iterator.go | 8 ++--- .../txs/executor/proposal_tx_executor_test.go | 22 ++++++------- .../txs/executor/standard_tx_executor_test.go | 24 +++++++------- vms/platformvm/vm_test.go | 32 +++++++++---------- 4 files changed, 43 insertions(+), 43 deletions(-) diff --git a/vms/platformvm/state/disk_staker_diff_iterator.go b/vms/platformvm/state/disk_staker_diff_iterator.go index df4b2e088353..690962ae8c96 100644 --- a/vms/platformvm/state/disk_staker_diff_iterator.go +++ b/vms/platformvm/state/disk_staker_diff_iterator.go @@ -52,13 +52,13 @@ func unmarshalDiffKey(key []byte) (ids.ID, uint64, ids.NodeID, error) { return ids.Empty, 0, ids.EmptyNodeID, errUnexpectedDiffKeyLength } var ( - subnetID ids.ID - nodeID ids.NodeID + subnetID ids.ID + shortNodeID ids.ShortNodeID ) copy(subnetID[:], key) height := unpackIterableHeight(key[ids.IDLen:]) - copy(nodeID.ShortNodeID.Bytes(), key[diffKeyNodeIDOffset:]) - return subnetID, height, nodeID, nil + copy(shortNodeID[:], key[diffKeyNodeIDOffset:]) + return subnetID, height, shortNodeID.NodeID(), nil } func marshalWeightDiff(diff *ValidatorWeightDiff) []byte { diff --git a/vms/platformvm/txs/executor/proposal_tx_executor_test.go b/vms/platformvm/txs/executor/proposal_tx_executor_test.go index 3ecb5a6b00dc..b188c6e33549 100644 --- a/vms/platformvm/txs/executor/proposal_tx_executor_test.go +++ b/vms/platformvm/txs/executor/proposal_tx_executor_test.go @@ -292,7 +292,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - nodeID := genesisNodeIDs[0] + shortNodeID := genesisNodeIDs[0] { // Case: Proposed validator currently validating primary network // but stops validating subnet after stops validating primary network @@ -301,7 +301,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID.NodeID(), + NodeID: shortNodeID.NodeID(), Start: uint64(defaultValidateStartTime.Unix()) + 1, End: uint64(defaultValidateEndTime.Unix()) + 1, Wght: defaultWeight, @@ -340,7 +340,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID.NodeID(), + NodeID: shortNodeID.NodeID(), Start: uint64(defaultValidateStartTime.Unix()) + 1, End: uint64(defaultValidateEndTime.Unix()), Wght: defaultWeight, @@ -566,7 +566,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID.NodeID(), + NodeID: shortNodeID.NodeID(), Start: uint64(newTimestamp.Unix()), End: uint64(newTimestamp.Add(defaultMinStakingDuration).Unix()), Wght: defaultWeight, @@ -605,7 +605,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { uSubnetTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID.NodeID(), + NodeID: shortNodeID.NodeID(), Start: uint64(defaultValidateStartTime.Unix()), End: uint64(defaultValidateEndTime.Unix()), Wght: defaultWeight, @@ -637,7 +637,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID.NodeID(), + NodeID: shortNodeID.NodeID(), Start: uint64(defaultValidateStartTime.Unix()) + 1, End: uint64(defaultValidateEndTime.Unix()), Wght: defaultWeight, @@ -677,7 +677,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID.NodeID(), + NodeID: shortNodeID.NodeID(), Start: uint64(defaultValidateStartTime.Unix()) + 1, End: uint64(defaultValidateStartTime.Add(defaultMinStakingDuration).Unix()) + 1, Wght: defaultWeight, @@ -720,7 +720,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID.NodeID(), + NodeID: shortNodeID.NodeID(), Start: uint64(defaultValidateStartTime.Unix()) + 1, End: uint64(defaultValidateStartTime.Add(defaultMinStakingDuration).Unix()) + 1, Wght: defaultWeight, @@ -762,7 +762,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID.NodeID(), + NodeID: shortNodeID.NodeID(), Start: uint64(defaultValidateStartTime.Unix()) + 1, End: uint64(defaultValidateStartTime.Add(defaultMinStakingDuration).Unix()) + 1, Wght: defaultWeight, @@ -855,13 +855,13 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { } { - nodeID := genesisNodeIDs[0] + shortNodeID := genesisNodeIDs[0] // Case: Validator already validating primary network builder, signer := env.factory.NewWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ - NodeID: nodeID.NodeID(), + NodeID: shortNodeID.NodeID(), Start: uint64(defaultValidateStartTime.Unix()) + 1, End: uint64(defaultValidateEndTime.Unix()), Wght: env.config.MinValidatorStake, diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index 475128a432db..602618375115 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -374,7 +374,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - nodeID := genesisNodeIDs[0] + shortNodeID := genesisNodeIDs[0] { // Case: Proposed validator currently validating primary network @@ -385,7 +385,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID.NodeID(), + NodeID: shortNodeID.NodeID(), Start: uint64(startTime.Unix()), End: uint64(defaultValidateEndTime.Unix()) + 1, Wght: defaultWeight, @@ -420,7 +420,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID.NodeID(), + NodeID: shortNodeID.NodeID(), Start: uint64(defaultValidateStartTime.Unix() + 1), End: uint64(defaultValidateEndTime.Unix()), Wght: defaultWeight, @@ -626,7 +626,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID.NodeID(), + NodeID: shortNodeID.NodeID(), Start: uint64(newTimestamp.Unix()), End: uint64(newTimestamp.Add(defaultMinStakingDuration).Unix()), Wght: defaultWeight, @@ -661,7 +661,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { uSubnetTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID.NodeID(), + NodeID: shortNodeID.NodeID(), Start: uint64(defaultValidateStartTime.Unix()), End: uint64(defaultValidateEndTime.Unix()), Wght: defaultWeight, @@ -694,7 +694,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID.NodeID(), + NodeID: shortNodeID.NodeID(), Start: uint64(startTime.Unix()), End: uint64(defaultValidateEndTime.Unix()), Wght: defaultWeight, @@ -731,7 +731,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID.NodeID(), + NodeID: shortNodeID.NodeID(), Start: uint64(startTime.Unix()), End: uint64(startTime.Add(defaultMinStakingDuration).Unix()) + 1, Wght: defaultWeight, @@ -771,7 +771,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID.NodeID(), + NodeID: shortNodeID.NodeID(), Start: uint64(startTime.Unix()), End: uint64(startTime.Add(defaultMinStakingDuration).Unix()), Wght: defaultWeight, @@ -811,7 +811,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID.NodeID(), + NodeID: shortNodeID.NodeID(), Start: uint64(startTime.Unix()), End: uint64(startTime.Add(defaultMinStakingDuration).Unix()), Wght: defaultWeight, @@ -850,7 +850,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID.NodeID(), + NodeID: shortNodeID.NodeID(), Start: uint64(startTime.Unix()) + 1, End: uint64(startTime.Add(defaultMinStakingDuration).Unix()) + 1, Wght: defaultWeight, @@ -897,13 +897,13 @@ func TestEtnaStandardTxExecutorAddSubnetValidator(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - nodeID := genesisNodeIDs[0] + shortNodeID := genesisNodeIDs[0] builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID.NodeID(), + NodeID: shortNodeID.NodeID(), Start: uint64(defaultValidateStartTime.Unix() + 1), End: uint64(defaultValidateEndTime.Unix()), Wght: defaultWeight, diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index ff7cf891e760..aecd1668a02a 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -612,9 +612,9 @@ func TestAddSubnetValidatorAccept(t *testing.T) { defer vm.ctx.Lock.Unlock() var ( - startTime = vm.clock.Time().Add(txexecutor.SyncBound).Add(1 * time.Second) - endTime = startTime.Add(defaultMinStakingDuration) - nodeID = genesisNodeIDs[0] + startTime = vm.clock.Time().Add(txexecutor.SyncBound).Add(1 * time.Second) + endTime = startTime.Add(defaultMinStakingDuration) + shortNodeID = genesisNodeIDs[0] ) // create valid tx @@ -624,7 +624,7 @@ func TestAddSubnetValidatorAccept(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID.NodeID(), + NodeID: shortNodeID.NodeID(), Start: uint64(startTime.Unix()), End: uint64(endTime.Unix()), Wght: defaultWeight, @@ -652,7 +652,7 @@ func TestAddSubnetValidatorAccept(t *testing.T) { require.Equal(status.Committed, txStatus) // Verify that new validator is in current validator set - _, err = vm.state.GetCurrentValidator(testSubnet1.ID(), nodeID.NodeID()) + _, err = vm.state.GetCurrentValidator(testSubnet1.ID(), shortNodeID.NodeID()) require.NoError(err) } @@ -664,9 +664,9 @@ func TestAddSubnetValidatorReject(t *testing.T) { defer vm.ctx.Lock.Unlock() var ( - startTime = vm.clock.Time().Add(txexecutor.SyncBound).Add(1 * time.Second) - endTime = startTime.Add(defaultMinStakingDuration) - nodeID = genesisNodeIDs[0] + startTime = vm.clock.Time().Add(txexecutor.SyncBound).Add(1 * time.Second) + endTime = startTime.Add(defaultMinStakingDuration) + shortNodeID = genesisNodeIDs[0] ) // create valid tx @@ -676,7 +676,7 @@ func TestAddSubnetValidatorReject(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID.NodeID(), + NodeID: shortNodeID.NodeID(), Start: uint64(startTime.Unix()), End: uint64(endTime.Unix()), Wght: defaultWeight, @@ -703,7 +703,7 @@ func TestAddSubnetValidatorReject(t *testing.T) { require.ErrorIs(err, database.ErrNotFound) // Verify that new validator NOT in validator set - _, err = vm.state.GetCurrentValidator(testSubnet1.ID(), nodeID.NodeID()) + _, err = vm.state.GetCurrentValidator(testSubnet1.ID(), shortNodeID.NodeID()) require.ErrorIs(err, database.ErrNotFound) } @@ -953,14 +953,14 @@ func TestCreateSubnet(t *testing.T) { require.Contains(subnetIDs, subnetID) // Now that we've created a new subnet, add a validator to that subnet - nodeID := genesisNodeIDs[0] + shortNodeID := genesisNodeIDs[0] startTime := vm.clock.Time().Add(txexecutor.SyncBound).Add(1 * time.Second) endTime := startTime.Add(defaultMinStakingDuration) // [startTime, endTime] is subset of time keys[0] validates default subnet so tx is valid uAddValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID.NodeID(), + NodeID: shortNodeID.NodeID(), Start: uint64(startTime.Unix()), End: uint64(endTime.Unix()), Wght: defaultWeight, @@ -988,10 +988,10 @@ func TestCreateSubnet(t *testing.T) { require.NoError(err) require.Equal(status.Committed, txStatus) - _, err = vm.state.GetPendingValidator(subnetID, nodeID.NodeID()) + _, err = vm.state.GetPendingValidator(subnetID, shortNodeID.NodeID()) require.ErrorIs(err, database.ErrNotFound) - _, err = vm.state.GetCurrentValidator(subnetID, nodeID.NodeID()) + _, err = vm.state.GetCurrentValidator(subnetID, shortNodeID.NodeID()) require.NoError(err) // fast forward clock to time validator should stop validating @@ -1001,10 +1001,10 @@ func TestCreateSubnet(t *testing.T) { require.NoError(blk.Verify(context.Background())) require.NoError(blk.Accept(context.Background())) // remove validator from current validator set - _, err = vm.state.GetPendingValidator(subnetID, nodeID.NodeID()) + _, err = vm.state.GetPendingValidator(subnetID, shortNodeID.NodeID()) require.ErrorIs(err, database.ErrNotFound) - _, err = vm.state.GetCurrentValidator(subnetID, nodeID.NodeID()) + _, err = vm.state.GetCurrentValidator(subnetID, shortNodeID.NodeID()) require.ErrorIs(err, database.ErrNotFound) } From 79cc15cf904c1b2a8be9a14781592585ec3b8b1c Mon Sep 17 00:00:00 2001 From: tsachiherman <24438559+tsachiherman@users.noreply.github.com> Date: Thu, 22 Aug 2024 13:24:03 -0400 Subject: [PATCH 08/17] update --- ids/node_id.go | 8 -------- network/network_test.go | 4 ++-- network/peer/peer_test.go | 2 +- network/peer/upgrader.go | 2 +- node/node.go | 2 +- tests/fixture/tmpnet/node.go | 2 +- utils/ips/claimed_ip_port.go | 2 +- vms/proposervm/batched_vm_test.go | 2 +- vms/proposervm/block/block.go | 2 +- vms/proposervm/block/build.go | 2 +- vms/proposervm/block/build_test.go | 2 +- vms/proposervm/state_syncable_vm_test.go | 2 +- vms/proposervm/vm_test.go | 16 ++++++++-------- 13 files changed, 20 insertions(+), 28 deletions(-) diff --git a/ids/node_id.go b/ids/node_id.go index f1ff41dd3309..c57bcdea22ed 100644 --- a/ids/node_id.go +++ b/ids/node_id.go @@ -4,9 +4,7 @@ package ids import ( - "github.com/ava-labs/avalanchego/staking" "github.com/ava-labs/avalanchego/utils" - "github.com/ava-labs/avalanchego/utils/hashing" ) const ( @@ -28,12 +26,6 @@ func (id NodeID) Compare(other NodeID) int { return id.ShortNodeID.Compare(other.ShortNodeID) } -func NodeIDFromCert(cert *staking.Certificate) NodeID { - return NodeID{ - ShortNodeID: ShortNodeID(hashing.ComputeHash160Array(hashing.ComputeHash256(cert.Raw))), - } -} - // NodeIDFromString is the inverse of NodeID.String() func NodeIDFromString(nodeIDStr string) (NodeID, error) { asShort, err := ShortFromPrefixedString(nodeIDStr, NodeIDPrefix) diff --git a/network/network_test.go b/network/network_test.go index a79d5d0cf717..6b2b81fd24f9 100644 --- a/network/network_test.go +++ b/network/network_test.go @@ -172,7 +172,7 @@ func newTestNetwork(t *testing.T, count int) (*testDialer, []*testListener, []id cert, err := staking.ParseCertificate(tlsCert.Leaf.Raw) require.NoError(t, err) - nodeID := ids.NodeIDFromCert(cert) + nodeID := ids.ShortNodeIDFromCert(cert).NodeID() blsKey, err := bls.NewSecretKey() require.NoError(t, err) @@ -411,7 +411,7 @@ func TestTrackVerifiesSignatures(t *testing.T) { cert, err := staking.ParseCertificate(tlsCert.Leaf.Raw) require.NoError(err) - nodeID := ids.NodeIDFromCert(cert) + nodeID := ids.ShortNodeIDFromCert(cert).NodeID() require.NoError(network.config.Validators.AddStaker(constants.PrimaryNetworkID, nodeID, nil, ids.Empty, 1)) diff --git a/network/peer/peer_test.go b/network/peer/peer_test.go index 0ae75b571f27..7942df927c97 100644 --- a/network/peer/peer_test.go +++ b/network/peer/peer_test.go @@ -105,7 +105,7 @@ func newRawTestPeer(t *testing.T, config Config) *rawTestPeer { require.NoError(err) cert, err := staking.ParseCertificate(tlsCert.Leaf.Raw) require.NoError(err) - config.MyNodeID = ids.NodeIDFromCert(cert) + config.MyNodeID = ids.ShortNodeIDFromCert(cert).NodeID() ip := utils.NewAtomic(netip.AddrPortFrom( netip.IPv6Loopback(), diff --git a/network/peer/upgrader.go b/network/peer/upgrader.go index ec39c87136d2..d345db08ca9a 100644 --- a/network/peer/upgrader.go +++ b/network/peer/upgrader.go @@ -75,6 +75,6 @@ func connToIDAndCert(conn *tls.Conn, invalidCerts prometheus.Counter) (ids.NodeI return ids.EmptyNodeID, nil, nil, err } - nodeID := ids.NodeIDFromCert(peerCert) + nodeID := ids.ShortNodeIDFromCert(peerCert).NodeID() return nodeID, conn, peerCert, nil } diff --git a/node/node.go b/node/node.go index b2aba9314439..80ae5f0fc6e8 100644 --- a/node/node.go +++ b/node/node.go @@ -133,7 +133,7 @@ func New( LogFactory: logFactory, StakingTLSSigner: config.StakingTLSCert.PrivateKey.(crypto.Signer), StakingTLSCert: stakingCert, - ID: ids.NodeIDFromCert(stakingCert), + ID: ids.ShortNodeIDFromCert(stakingCert).NodeID(), Config: config, } diff --git a/tests/fixture/tmpnet/node.go b/tests/fixture/tmpnet/node.go index 3a6076af1283..db38479ea928 100644 --- a/tests/fixture/tmpnet/node.go +++ b/tests/fixture/tmpnet/node.go @@ -359,7 +359,7 @@ func (n *Node) EnsureNodeID() error { if err != nil { return fmt.Errorf("failed to ensure node ID: failed to parse staking cert: %w", err) } - n.NodeID = ids.NodeIDFromCert(stakingCert) + n.NodeID = ids.ShortNodeIDFromCert(stakingCert).NodeID() return nil } diff --git a/utils/ips/claimed_ip_port.go b/utils/ips/claimed_ip_port.go index c7cf39a9d446..6ed004acc7d7 100644 --- a/utils/ips/claimed_ip_port.go +++ b/utils/ips/claimed_ip_port.go @@ -50,7 +50,7 @@ func NewClaimedIPPort( AddrPort: ipPort, Timestamp: timestamp, Signature: signature, - NodeID: ids.NodeIDFromCert(cert), + NodeID: ids.ShortNodeIDFromCert(cert).NodeID(), } packer := wrappers.Packer{ diff --git a/vms/proposervm/batched_vm_test.go b/vms/proposervm/batched_vm_test.go index d8b50dc94e67..a1d4bf37bf82 100644 --- a/vms/proposervm/batched_vm_test.go +++ b/vms/proposervm/batched_vm_test.go @@ -1017,7 +1017,7 @@ func initTestRemoteProposerVM( } ctx := snowtest.Context(t, snowtest.CChainID) - ctx.NodeID = ids.NodeIDFromCert(pTestCert) + ctx.NodeID = ids.ShortNodeIDFromCert(pTestCert).NodeID() ctx.ValidatorState = valState require.NoError(proVM.Initialize( diff --git a/vms/proposervm/block/block.go b/vms/proposervm/block/block.go index 68da910e1dbd..e61ab5139960 100644 --- a/vms/proposervm/block/block.go +++ b/vms/proposervm/block/block.go @@ -98,7 +98,7 @@ func (b *statelessBlock) initialize(bytes []byte) error { return fmt.Errorf("%w: %w", errInvalidCertificate, err) } - b.proposer = ids.NodeIDFromCert(b.cert) + b.proposer = ids.ShortNodeIDFromCert(b.cert).NodeID() return nil } diff --git a/vms/proposervm/block/build.go b/vms/proposervm/block/build.go index 228ab97604da..bca8ddb4c374 100644 --- a/vms/proposervm/block/build.go +++ b/vms/proposervm/block/build.go @@ -58,7 +58,7 @@ func Build( }, timestamp: timestamp, cert: cert, - proposer: ids.NodeIDFromCert(cert), + proposer: ids.ShortNodeIDFromCert(cert).NodeID(), } var blockIntf SignedBlock = block diff --git a/vms/proposervm/block/build_test.go b/vms/proposervm/block/build_test.go index 2ed9510c696c..774beaba8731 100644 --- a/vms/proposervm/block/build_test.go +++ b/vms/proposervm/block/build_test.go @@ -29,7 +29,7 @@ func TestBuild(t *testing.T) { cert, err := staking.ParseCertificate(tlsCert.Leaf.Raw) require.NoError(err) key := tlsCert.PrivateKey.(crypto.Signer) - nodeID := ids.NodeIDFromCert(cert) + nodeID := ids.ShortNodeIDFromCert(cert).NodeID() builtBlock, err := Build( parentID, diff --git a/vms/proposervm/state_syncable_vm_test.go b/vms/proposervm/state_syncable_vm_test.go index 41f699790934..bde2614db09c 100644 --- a/vms/proposervm/state_syncable_vm_test.go +++ b/vms/proposervm/state_syncable_vm_test.go @@ -70,7 +70,7 @@ func helperBuildStateSyncTestObjects(t *testing.T) (*fullVM, *VM) { ) ctx := snowtest.Context(t, snowtest.CChainID) - ctx.NodeID = ids.NodeIDFromCert(pTestCert) + ctx.NodeID = ids.ShortNodeIDFromCert(pTestCert).NodeID() require.NoError(vm.Initialize( context.Background(), diff --git a/vms/proposervm/vm_test.go b/vms/proposervm/vm_test.go index a689e7d32013..29aa7df70770 100644 --- a/vms/proposervm/vm_test.go +++ b/vms/proposervm/vm_test.go @@ -180,7 +180,7 @@ func initTestProposerVM( } ctx := snowtest.Context(t, ids.ID{1}) - ctx.NodeID = ids.NodeIDFromCert(pTestCert) + ctx.NodeID = ids.ShortNodeIDFromCert(pTestCert).NodeID() ctx.ValidatorState = valState db := prefixdb.New([]byte{0}, memdb.New()) @@ -838,7 +838,7 @@ func TestExpiredBuildBlock(t *testing.T) { } ctx := snowtest.Context(t, snowtest.CChainID) - ctx.NodeID = ids.NodeIDFromCert(pTestCert) + ctx.NodeID = ids.ShortNodeIDFromCert(pTestCert).NodeID() ctx.ValidatorState = valState toEngine := make(chan common.Message, 1) @@ -1117,7 +1117,7 @@ func TestInnerVMRollback(t *testing.T) { } ctx := snowtest.Context(t, snowtest.CChainID) - ctx.NodeID = ids.NodeIDFromCert(pTestCert) + ctx.NodeID = ids.ShortNodeIDFromCert(pTestCert).NodeID() ctx.ValidatorState = valState db := memdb.New() @@ -1635,7 +1635,7 @@ func TestRejectedHeightNotIndexed(t *testing.T) { } ctx := snowtest.Context(t, snowtest.CChainID) - ctx.NodeID = ids.NodeIDFromCert(pTestCert) + ctx.NodeID = ids.ShortNodeIDFromCert(pTestCert).NodeID() ctx.ValidatorState = valState require.NoError(proVM.Initialize( @@ -1804,7 +1804,7 @@ func TestRejectedOptionHeightNotIndexed(t *testing.T) { } ctx := snowtest.Context(t, snowtest.CChainID) - ctx.NodeID = ids.NodeIDFromCert(pTestCert) + ctx.NodeID = ids.ShortNodeIDFromCert(pTestCert).NodeID() ctx.ValidatorState = valState require.NoError(proVM.Initialize( @@ -1921,7 +1921,7 @@ func TestVMInnerBlkCache(t *testing.T) { } ctx := snowtest.Context(t, snowtest.CChainID) - ctx.NodeID = ids.NodeIDFromCert(pTestCert) + ctx.NodeID = ids.ShortNodeIDFromCert(pTestCert).NodeID() require.NoError(vm.Initialize( context.Background(), @@ -2032,7 +2032,7 @@ func TestVM_VerifyBlockWithContext(t *testing.T) { } snowCtx := snowtest.Context(t, snowtest.CChainID) - snowCtx.NodeID = ids.NodeIDFromCert(pTestCert) + snowCtx.NodeID = ids.ShortNodeIDFromCert(pTestCert).NodeID() require.NoError(vm.Initialize( context.Background(), @@ -2179,7 +2179,7 @@ func TestHistoricalBlockDeletion(t *testing.T) { } ctx := snowtest.Context(t, snowtest.CChainID) - ctx.NodeID = ids.NodeIDFromCert(pTestCert) + ctx.NodeID = ids.ShortNodeIDFromCert(pTestCert).NodeID() ctx.ValidatorState = &validatorstest.State{ T: t, GetMinimumHeightF: func(context.Context) (uint64, error) { From 169d8bbc1bd8734b7f59cf2a750c1b2cff66f411 Mon Sep 17 00:00:00 2001 From: tsachiherman <24438559+tsachiherman@users.noreply.github.com> Date: Thu, 22 Aug 2024 13:30:26 -0400 Subject: [PATCH 09/17] fix lint --- ids/node_id.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ids/node_id.go b/ids/node_id.go index c57bcdea22ed..be0e6fa89b29 100644 --- a/ids/node_id.go +++ b/ids/node_id.go @@ -3,9 +3,7 @@ package ids -import ( - "github.com/ava-labs/avalanchego/utils" -) +import "github.com/ava-labs/avalanchego/utils" const ( NodeIDPrefix = "NodeID-" From 108bd24a21a9bb1626f2405876a024a4334c9c9c Mon Sep 17 00:00:00 2001 From: tsachiherman <24438559+tsachiherman@users.noreply.github.com> Date: Fri, 23 Aug 2024 11:53:36 -0400 Subject: [PATCH 10/17] fix merge errors --- vms/platformvm/service_test.go | 2 +- vms/platformvm/validator_set_property_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index 69854434bb2b..44bb0ef42b5d 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -642,7 +642,7 @@ func TestGetCurrentValidators(t *testing.T) { found := false for i := 0; i < len(response.Validators); i++ { gotVdr := response.Validators[i].(pchainapi.PermissionlessValidator) - if gotVdr.NodeID.Compare(vdr.NodeID.NodeID()) != 0 { + if gotVdr.NodeID.Compare(nodeID) != 0 { continue } diff --git a/vms/platformvm/validator_set_property_test.go b/vms/platformvm/validator_set_property_test.go index 44ba02e0e1a7..802c2d2c2435 100644 --- a/vms/platformvm/validator_set_property_test.go +++ b/vms/platformvm/validator_set_property_test.go @@ -686,7 +686,7 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) { chainDB, genesistest.NewBytes(t, genesistest.Config{ NodeIDs: []ids.NodeID{ - genesistest.DefaultNodeIDs[len(genesistest.DefaultNodeIDs)-1], + genesistest.DefaultNodeIDs[len(genesistest.DefaultNodeIDs)-1].NodeID(), }, ValidatorEndTime: mockable.MaxTime, }), From ff2dc604a703e2c4bef271aa7af92367e6646472 Mon Sep 17 00:00:00 2001 From: tsachiherman <24438559+tsachiherman@users.noreply.github.com> Date: Tue, 27 Aug 2024 16:08:07 -0400 Subject: [PATCH 11/17] update per CR --- ids/node_id.go | 1 - tests/e2e/p/elastic_subnets.go | 5 +- tests/e2e/p/interchain_workflow.go | 6 +- tests/e2e/p/staking_rewards.go | 12 ++- tests/e2e/p/validator_sets.go | 5 +- tests/e2e/p/workflow.go | 4 +- tests/fixture/tmpnet/subnet.go | 8 +- vms/platformvm/api/static_service.go | 2 +- vms/platformvm/block/builder/builder_test.go | 8 +- vms/platformvm/block/executor/block_test.go | 10 +- vms/platformvm/block/executor/helpers_test.go | 8 +- .../block/executor/proposal_block_test.go | 82 +++++++------- .../block/executor/standard_block_test.go | 60 +++++------ vms/platformvm/genesis/genesistest/genesis.go | 6 +- vms/platformvm/service_test.go | 8 +- .../state/disk_staker_diff_iterator.go | 2 +- vms/platformvm/state/staker_test.go | 2 +- vms/platformvm/state/state_test.go | 30 +++--- vms/platformvm/txs/add_delegator_test.go | 8 +- vms/platformvm/txs/add_delegator_tx.go | 2 +- .../txs/add_permissionless_delegator_tx.go | 2 +- .../add_permissionless_delegator_tx_test.go | 8 +- .../txs/add_permissionless_validator_tx.go | 4 +- .../add_permissionless_validator_tx_test.go | 30 +++--- .../txs/add_subnet_validator_test.go | 8 +- vms/platformvm/txs/add_subnet_validator_tx.go | 2 +- vms/platformvm/txs/add_validator_test.go | 8 +- vms/platformvm/txs/add_validator_tx.go | 2 +- .../txs/executor/advance_time_test.go | 84 +++++++-------- .../txs/executor/proposal_tx_executor_test.go | 34 +++--- .../txs/executor/reward_validator_test.go | 14 +-- .../txs/executor/staker_tx_verification.go | 16 +-- .../executor/staker_tx_verification_test.go | 2 +- .../txs/executor/standard_tx_executor.go | 6 +- .../txs/executor/standard_tx_executor_test.go | 64 ++++++----- vms/platformvm/txs/fee/complexity.go | 4 +- .../txs/remove_subnet_validator_tx.go | 2 +- .../txs/remove_subnet_validator_tx_test.go | 10 +- vms/platformvm/txs/txheap/by_end_time_test.go | 6 +- vms/platformvm/txs/validator.go | 2 +- vms/platformvm/txs/validator_test.go | 2 +- vms/platformvm/validator_set_property_test.go | 16 +-- vms/platformvm/vm_regression_test.go | 102 +++++++++--------- vms/platformvm/vm_test.go | 24 ++--- wallet/chain/p/builder/builder.go | 4 +- .../chain/p/builder/builder_with_options.go | 2 +- wallet/chain/p/builder_test.go | 2 +- wallet/chain/p/wallet/wallet.go | 4 +- wallet/chain/p/wallet/with_options.go | 2 +- wallet/subnet/primary/example_test.go | 4 +- .../add-permissioned-subnet-validator/main.go | 6 +- .../examples/add-primary-validator/main.go | 6 +- .../examples/remove-subnet-validator/main.go | 2 +- 53 files changed, 398 insertions(+), 355 deletions(-) diff --git a/ids/node_id.go b/ids/node_id.go index be0e6fa89b29..9cccc9cebf13 100644 --- a/ids/node_id.go +++ b/ids/node_id.go @@ -7,7 +7,6 @@ import "github.com/ava-labs/avalanchego/utils" const ( NodeIDPrefix = "NodeID-" - NodeIDLen = ShortIDLen ) var ( diff --git a/tests/e2e/p/elastic_subnets.go b/tests/e2e/p/elastic_subnets.go index 100ff81780ce..26527e9d583c 100644 --- a/tests/e2e/p/elastic_subnets.go +++ b/tests/e2e/p/elastic_subnets.go @@ -55,12 +55,13 @@ var _ = e2e.DescribePChain("[Elastic Subnets]", func() { xContext := xBuilder.Context() xChainID := xContext.BlockchainID - var validatorID ids.NodeID + var validatorID ids.ShortNodeID tc.By("retrieving the node ID of a primary network validator", func() { pChainClient := platformvm.NewClient(nodeURI.URI) validatorIDs, err := pChainClient.SampleValidators(tc.DefaultContext(), constants.PrimaryNetworkID, 1) require.NoError(err) - validatorID = validatorIDs[0] + validatorID, err = ids.ShortNodeIDFromNodeID(validatorIDs[0]) + require.NoError(err) }) owner := &secp256k1fx.OutputOwners{ diff --git a/tests/e2e/p/interchain_workflow.go b/tests/e2e/p/interchain_workflow.go index e612658bb8fe..9fdff2421f6d 100644 --- a/tests/e2e/p/interchain_workflow.go +++ b/tests/e2e/p/interchain_workflow.go @@ -117,6 +117,8 @@ var _ = e2e.DescribePChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL infoClient := info.NewClient(node.URI) nodeID, nodePOP, err := infoClient.GetNodeID(tc.DefaultContext()) require.NoError(err) + shortNodeID, err := ids.ShortNodeIDFromNodeID(nodeID) + require.NoError(err) // Adding a validator should not break interchain transfer. endTime := time.Now().Add(30 * time.Second) @@ -134,7 +136,7 @@ var _ = e2e.DescribePChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL _, err = pWallet.IssueAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID, + NodeID: shortNodeID, End: uint64(endTime.Unix()), Wght: weight, }, @@ -167,7 +169,7 @@ var _ = e2e.DescribePChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL _, err = pWallet.IssueAddPermissionlessDelegatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID, + NodeID: shortNodeID, End: uint64(endTime.Unix()), Wght: weight, }, diff --git a/tests/e2e/p/staking_rewards.go b/tests/e2e/p/staking_rewards.go index 3f6023780f22..78300dbd2a34 100644 --- a/tests/e2e/p/staking_rewards.go +++ b/tests/e2e/p/staking_rewards.go @@ -70,11 +70,15 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() { alphaInfoClient := info.NewClient(alphaNode.URI) alphaNodeID, alphaPOP, err := alphaInfoClient.GetNodeID(tc.DefaultContext()) require.NoError(err) + alphaShortNodeID, err := ids.ShortNodeIDFromNodeID(alphaNodeID) + require.NoError(err) tc.By("retrieving beta node id and pop") betaInfoClient := info.NewClient(betaNode.URI) betaNodeID, betaPOP, err := betaInfoClient.GetNodeID(tc.DefaultContext()) require.NoError(err) + betaShortNodeID, err := ids.ShortNodeIDFromNodeID(betaNodeID) + require.NoError(err) tc.By("creating keychain and P-Chain wallet") var ( @@ -118,7 +122,7 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() { _, err := pWallet.IssueAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: alphaNodeID, + NodeID: alphaShortNodeID, End: uint64(endTime.Unix()), Wght: weight, }, @@ -147,7 +151,7 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() { _, err := pWallet.IssueAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: betaNodeID, + NodeID: betaShortNodeID, End: uint64(betaValidatorEndTime.Unix()), Wght: weight, }, @@ -180,7 +184,7 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() { _, err := pWallet.IssueAddPermissionlessDelegatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: alphaNodeID, + NodeID: alphaShortNodeID, End: uint64(endTime.Unix()), Wght: weight, }, @@ -203,7 +207,7 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() { _, err := pWallet.IssueAddPermissionlessDelegatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: betaNodeID, + NodeID: betaShortNodeID, End: uint64(endTime.Unix()), Wght: weight, }, diff --git a/tests/e2e/p/validator_sets.go b/tests/e2e/p/validator_sets.go index 81c6ab8178a9..5fb245edcffa 100644 --- a/tests/e2e/p/validator_sets.go +++ b/tests/e2e/p/validator_sets.go @@ -44,6 +44,9 @@ var _ = e2e.DescribePChain("[Validator Sets]", func() { avaxAssetID = pContext.AVAXAssetID ) + shortNodeID, err := ids.ShortNodeIDFromNodeID(nodeURI.NodeID) + require.NoError(err) + const delegatorCount = 15 tc.By(fmt.Sprintf("adding %d delegators", delegatorCount), func() { var ( @@ -57,7 +60,7 @@ var _ = e2e.DescribePChain("[Validator Sets]", func() { _, err := pWallet.IssueAddPermissionlessDelegatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeURI.NodeID, + NodeID: shortNodeID, End: uint64(endTime.Unix()), Wght: weight, }, diff --git a/tests/e2e/p/workflow.go b/tests/e2e/p/workflow.go index 634a660f95a6..e7800dd90d9e 100644 --- a/tests/e2e/p/workflow.go +++ b/tests/e2e/p/workflow.go @@ -100,12 +100,12 @@ var _ = e2e.DescribePChain("[Workflow]", func() { // Use a random node ID to ensure that repeated test runs will succeed // against a network that persists across runs. - validatorID, err := ids.ToShortNodeID(utils.RandomBytes(ids.NodeIDLen)) + validatorID, err := ids.ToShortNodeID(utils.RandomBytes(ids.ShortNodeIDLen)) require.NoError(err) vdr := &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: validatorID.NodeID(), + NodeID: validatorID, End: uint64(time.Now().Add(72 * time.Hour).Unix()), Wght: minValStake, }, diff --git a/tests/fixture/tmpnet/subnet.go b/tests/fixture/tmpnet/subnet.go index a9062f2fb5cc..3d70e5d39351 100644 --- a/tests/fixture/tmpnet/subnet.go +++ b/tests/fixture/tmpnet/subnet.go @@ -189,11 +189,15 @@ func (s *Subnet) AddValidators(ctx context.Context, w io.Writer, apiURI string, if !ok { return fmt.Errorf("failed to find end time for %s", node.NodeID) } + shortNodeID, err := ids.ShortNodeIDFromNodeID(node.NodeID) + if err != nil { + return err + } - _, err := pWallet.IssueAddSubnetValidatorTx( + _, err = pWallet.IssueAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: node.NodeID, + NodeID: shortNodeID, Start: uint64(startTime.Unix()), End: endTime, Wght: units.Schmeckle, diff --git a/vms/platformvm/api/static_service.go b/vms/platformvm/api/static_service.go index 7b45d0ab451b..521b37a3e20b 100644 --- a/vms/platformvm/api/static_service.go +++ b/vms/platformvm/api/static_service.go @@ -330,7 +330,7 @@ func (*StaticService) BuildGenesis(_ *http.Request, args *BuildGenesisArgs, repl BlockchainID: ids.Empty, }} validator = txs.Validator{ - NodeID: vdr.NodeID.NodeID(), + NodeID: vdr.NodeID, Start: uint64(args.Time), End: uint64(vdr.EndTime), Wght: weight, diff --git a/vms/platformvm/block/builder/builder_test.go b/vms/platformvm/block/builder/builder_test.go index 2d83b37615d0..d17cb41e8b83 100644 --- a/vms/platformvm/block/builder/builder_test.go +++ b/vms/platformvm/block/builder/builder_test.go @@ -103,7 +103,7 @@ func TestBuildBlockShouldReward(t *testing.T) { var ( now = env.backend.Clk.Time() - nodeID = ids.GenerateTestNodeID() + nodeID = ids.GenerateTestShortNodeID() defaultValidatorStake = 100 * units.MilliAvax validatorStartTime = now.Add(2 * txexecutor.SyncBound) @@ -163,7 +163,7 @@ func TestBuildBlockShouldReward(t *testing.T) { require.True(env.blkManager.SetPreference(blk.ID())) // Validator should now be current - staker, err := env.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID) + staker, err := env.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.NoError(err) require.Equal(txID, staker.TxID) @@ -327,7 +327,7 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) { utx1, err := builder1.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), Start: uint64(now.Unix()), End: uint64(validatorEndTime.Unix()), Wght: defaultValidatorStake, @@ -368,7 +368,7 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) { utx2, err := builder2.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), Start: uint64(now.Unix()), End: uint64(validator2EndTime.Unix()), Wght: defaultValidatorStake, diff --git a/vms/platformvm/block/executor/block_test.go b/vms/platformvm/block/executor/block_test.go index 27eaed415980..bc4d0dbde402 100644 --- a/vms/platformvm/block/executor/block_test.go +++ b/vms/platformvm/block/executor/block_test.go @@ -215,7 +215,7 @@ func TestBlockOptions(t *testing.T) { blkF: func(ctrl *gomock.Controller) *Block { var ( stakerTxID = ids.GenerateTestID() - nodeID = ids.GenerateTestNodeID() + nodeID = ids.GenerateTestShortNodeID() subnetID = ids.GenerateTestID() stakerTx = &txs.Tx{ Unsigned: &txs.AddPermissionlessValidatorTx{ @@ -266,7 +266,7 @@ func TestBlockOptions(t *testing.T) { blkF: func(ctrl *gomock.Controller) *Block { var ( stakerTxID = ids.GenerateTestID() - nodeID = ids.GenerateTestNodeID() + nodeID = ids.GenerateTestShortNodeID() subnetID = constants.PrimaryNetworkID stakerTx = &txs.Tx{ Unsigned: &txs.AddPermissionlessValidatorTx{ @@ -322,7 +322,7 @@ func TestBlockOptions(t *testing.T) { blkF: func(ctrl *gomock.Controller) *Block { var ( stakerTxID = ids.GenerateTestID() - nodeID = ids.GenerateTestNodeID() + nodeID = ids.GenerateTestShortNodeID() subnetID = ids.GenerateTestID() stakerTx = &txs.Tx{ Unsigned: &txs.AddPermissionlessValidatorTx{ @@ -378,7 +378,7 @@ func TestBlockOptions(t *testing.T) { blkF: func(ctrl *gomock.Controller) *Block { var ( stakerTxID = ids.GenerateTestID() - nodeID = ids.GenerateTestNodeID() + nodeID = ids.GenerateTestShortNodeID() subnetID = ids.GenerateTestID() stakerTx = &txs.Tx{ Unsigned: &txs.AddPermissionlessValidatorTx{ @@ -440,7 +440,7 @@ func TestBlockOptions(t *testing.T) { blkF: func(ctrl *gomock.Controller) *Block { var ( stakerTxID = ids.GenerateTestID() - nodeID = ids.GenerateTestNodeID() + nodeID = ids.GenerateTestShortNodeID() subnetID = ids.GenerateTestID() stakerTx = &txs.Tx{ Unsigned: &txs.AddPermissionlessValidatorTx{ diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index 947fd15a8691..e9ff3b633e52 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -69,7 +69,7 @@ var testSubnet1 *txs.Tx type stakerStatus uint type staker struct { - nodeID ids.NodeID + nodeID ids.ShortNodeID rewardAddress ids.ShortID startTime, endTime time.Time } @@ -79,8 +79,8 @@ type test struct { stakers []staker subnetStakers []staker advanceTimeTo []time.Time - expectedStakers map[ids.NodeID]stakerStatus - expectedSubnetStakers map[ids.NodeID]stakerStatus + expectedStakers map[ids.ShortNodeID]stakerStatus + expectedSubnetStakers map[ids.ShortNodeID]stakerStatus } type environment struct { @@ -351,7 +351,7 @@ func addPendingValidator( env *environment, startTime time.Time, endTime time.Time, - nodeID ids.NodeID, + nodeID ids.ShortNodeID, rewardAddress ids.ShortID, keys []*secp256k1.PrivateKey, ) (*txs.Tx, error) { diff --git a/vms/platformvm/block/executor/proposal_block_test.go b/vms/platformvm/block/executor/proposal_block_test.go index 54af982b2141..cf78fdbaee0f 100644 --- a/vms/platformvm/block/executor/proposal_block_test.go +++ b/vms/platformvm/block/executor/proposal_block_test.go @@ -374,44 +374,44 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { // so that TxID does not depend on the order we run tests. We also explicitly declare // the change address, to avoid picking a random one in case multiple funding keys are set. staker0 := staker{ - nodeID: ids.BuildTestNodeID([]byte{0xf0}), + nodeID: ids.BuildTestShortNodeID([]byte{0xf0}), rewardAddress: ids.ShortID{0xf0}, startTime: genesistest.DefaultValidatorStartTime, endTime: time.Time{}, // actual endTime depends on specific test } staker1 := staker{ - nodeID: ids.BuildTestNodeID([]byte{0xf1}), + nodeID: ids.BuildTestShortNodeID([]byte{0xf1}), rewardAddress: ids.ShortID{0xf1}, startTime: genesistest.DefaultValidatorStartTime.Add(1 * time.Minute), endTime: genesistest.DefaultValidatorStartTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute), } staker2 := staker{ - nodeID: ids.BuildTestNodeID([]byte{0xf2}), + nodeID: ids.BuildTestShortNodeID([]byte{0xf2}), rewardAddress: ids.ShortID{0xf2}, startTime: staker1.startTime.Add(1 * time.Minute), endTime: staker1.startTime.Add(1 * time.Minute).Add(defaultMinStakingDuration), } staker3 := staker{ - nodeID: ids.BuildTestNodeID([]byte{0xf3}), + nodeID: ids.BuildTestShortNodeID([]byte{0xf3}), rewardAddress: ids.ShortID{0xf3}, startTime: staker2.startTime.Add(1 * time.Minute), endTime: staker2.endTime.Add(1 * time.Minute), } staker3Sub := staker{ - nodeID: ids.BuildTestNodeID([]byte{0xf3}), + nodeID: ids.BuildTestShortNodeID([]byte{0xf3}), rewardAddress: ids.ShortID{0xff}, startTime: staker3.startTime.Add(1 * time.Minute), endTime: staker3.endTime.Add(-1 * time.Minute), } staker4 := staker{ - nodeID: ids.BuildTestNodeID([]byte{0xf4}), + nodeID: ids.BuildTestShortNodeID([]byte{0xf4}), rewardAddress: ids.ShortID{0xf4}, startTime: staker3.startTime, endTime: staker3.endTime, } staker5 := staker{ - nodeID: ids.BuildTestNodeID([]byte{0xf5}), + nodeID: ids.BuildTestShortNodeID([]byte{0xf5}), rewardAddress: ids.ShortID{0xf5}, startTime: staker2.endTime, endTime: staker2.endTime.Add(defaultMinStakingDuration), @@ -423,14 +423,14 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { stakers: []staker{staker1, staker2, staker3, staker4, staker5}, subnetStakers: []staker{staker1, staker2, staker3, staker4, staker5}, advanceTimeTo: []time.Time{staker1.startTime.Add(-1 * time.Second)}, - expectedStakers: map[ids.NodeID]stakerStatus{ + expectedStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: pending, staker2.nodeID: pending, staker3.nodeID: pending, staker4.nodeID: pending, staker5.nodeID: pending, }, - expectedSubnetStakers: map[ids.NodeID]stakerStatus{ + expectedSubnetStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: pending, staker2.nodeID: pending, staker3.nodeID: pending, @@ -443,14 +443,14 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { stakers: []staker{staker1, staker2, staker3, staker4, staker5}, subnetStakers: []staker{staker1}, advanceTimeTo: []time.Time{staker1.startTime}, - expectedStakers: map[ids.NodeID]stakerStatus{ + expectedStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: current, staker2.nodeID: pending, staker3.nodeID: pending, staker4.nodeID: pending, staker5.nodeID: pending, }, - expectedSubnetStakers: map[ids.NodeID]stakerStatus{ + expectedSubnetStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: current, staker2.nodeID: pending, staker3.nodeID: pending, @@ -462,7 +462,7 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { description: "advance time to the staker2 start", stakers: []staker{staker1, staker2, staker3, staker4, staker5}, advanceTimeTo: []time.Time{staker1.startTime, staker2.startTime}, - expectedStakers: map[ids.NodeID]stakerStatus{ + expectedStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: current, staker2.nodeID: current, staker3.nodeID: pending, @@ -475,14 +475,14 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { stakers: []staker{staker1, staker2, staker3, staker4, staker5}, subnetStakers: []staker{staker1, staker2, staker3Sub, staker4, staker5}, advanceTimeTo: []time.Time{staker1.startTime, staker2.startTime, staker3.startTime}, - expectedStakers: map[ids.NodeID]stakerStatus{ + expectedStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: current, staker2.nodeID: current, staker3.nodeID: current, staker4.nodeID: current, staker5.nodeID: pending, }, - expectedSubnetStakers: map[ids.NodeID]stakerStatus{ + expectedSubnetStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: current, staker2.nodeID: current, staker3Sub.nodeID: pending, @@ -495,14 +495,14 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { stakers: []staker{staker1, staker2, staker3, staker4, staker5}, subnetStakers: []staker{staker1, staker2, staker3Sub, staker4, staker5}, advanceTimeTo: []time.Time{staker1.startTime, staker2.startTime, staker3.startTime, staker3Sub.startTime}, - expectedStakers: map[ids.NodeID]stakerStatus{ + expectedStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: current, staker2.nodeID: current, staker3.nodeID: current, staker4.nodeID: current, staker5.nodeID: pending, }, - expectedSubnetStakers: map[ids.NodeID]stakerStatus{ + expectedSubnetStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: current, staker2.nodeID: current, staker3.nodeID: current, @@ -665,14 +665,14 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { for stakerNodeID, status := range test.expectedStakers { switch status { case pending: - _, err := env.state.GetPendingValidator(constants.PrimaryNetworkID, stakerNodeID) + _, err := env.state.GetPendingValidator(constants.PrimaryNetworkID, stakerNodeID.NodeID()) require.NoError(err) - _, ok := env.config.Validators.GetValidator(constants.PrimaryNetworkID, stakerNodeID) + _, ok := env.config.Validators.GetValidator(constants.PrimaryNetworkID, stakerNodeID.NodeID()) require.False(ok) case current: - _, err := env.state.GetCurrentValidator(constants.PrimaryNetworkID, stakerNodeID) + _, err := env.state.GetCurrentValidator(constants.PrimaryNetworkID, stakerNodeID.NodeID()) require.NoError(err) - _, ok := env.config.Validators.GetValidator(constants.PrimaryNetworkID, stakerNodeID) + _, ok := env.config.Validators.GetValidator(constants.PrimaryNetworkID, stakerNodeID.NodeID()) require.True(ok) } } @@ -680,10 +680,10 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { for stakerNodeID, status := range test.expectedSubnetStakers { switch status { case pending: - _, ok := env.config.Validators.GetValidator(subnetID, stakerNodeID) + _, ok := env.config.Validators.GetValidator(subnetID, stakerNodeID.NodeID()) require.False(ok) case current: - _, ok := env.config.Validators.GetValidator(subnetID, stakerNodeID) + _, ok := env.config.Validators.GetValidator(subnetID, stakerNodeID.NodeID()) require.True(ok) } } @@ -705,7 +705,7 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: subnetValidatorNodeID.NodeID(), + NodeID: subnetValidatorNodeID, Start: genesistest.DefaultValidatorStartTimeUnix, End: uint64(subnetVdr1EndTime.Unix()), Wght: 1, @@ -737,7 +737,7 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { utx, err = builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: subnetVdr2NodeID.NodeID(), + NodeID: subnetVdr2NodeID, Start: uint64(subnetVdr1EndTime.Add(time.Second).Unix()), End: uint64(subnetVdr1EndTime.Add(time.Second).Add(defaultMinStakingDuration).Unix()), Wght: 1, @@ -769,7 +769,7 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { staker0EndTime := subnetVdr1EndTime uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), Start: genesistest.DefaultValidatorStartTimeUnix, End: uint64(staker0EndTime.Unix()), Wght: 10, @@ -864,7 +864,7 @@ func TestBanffProposalBlockTrackedSubnet(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: subnetValidatorNodeID.NodeID(), + NodeID: subnetValidatorNodeID, Start: uint64(subnetVdr1StartTime.Unix()), End: uint64(subnetVdr1EndTime.Unix()), Wght: 1, @@ -896,7 +896,7 @@ func TestBanffProposalBlockTrackedSubnet(t *testing.T) { uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), Start: uint64(staker0StartTime.Unix()), End: uint64(staker0EndTime.Unix()), Wght: 10, @@ -968,7 +968,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { // Add a pending validator pendingValidatorStartTime := genesistest.DefaultValidatorStartTime.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMaxStakingDuration) - nodeID := ids.GenerateTestNodeID() + nodeID := ids.GenerateTestShortNodeID() rewardAddress := ids.GenerateTestShortID() _, err := addPendingValidator( env, @@ -987,7 +987,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddValidatorTx( &txs.Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), Start: uint64(staker0StartTime.Unix()), End: uint64(staker0EndTime.Unix()), Wght: 10, @@ -1048,7 +1048,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { require.NoError(commitBlk.Accept(context.Background())) // Test validator weight before delegation - vdrWeight := env.config.Validators.GetWeight(constants.PrimaryNetworkID, nodeID) + vdrWeight := env.config.Validators.GetWeight(constants.PrimaryNetworkID, nodeID.NodeID()) require.Equal(env.config.MinValidatorStake, vdrWeight) // Add delegator @@ -1089,7 +1089,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { builder, signer = env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err = builder.NewAddValidatorTx( &txs.Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), Start: uint64(staker0StartTime.Unix()), End: uint64(staker0EndTime.Unix()), Wght: 10, @@ -1151,7 +1151,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { require.NoError(commitBlk.Accept(context.Background())) // Test validator weight after delegation - vdrWeight = env.config.Validators.GetWeight(constants.PrimaryNetworkID, nodeID) + vdrWeight = env.config.Validators.GetWeight(constants.PrimaryNetworkID, nodeID.NodeID()) require.Equal(env.config.MinDelegatorStake+env.config.MinValidatorStake, vdrWeight) } @@ -1165,7 +1165,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMinStakingDuration) nodeIDKey, _ := secp256k1.NewPrivateKey() rewardAddress := nodeIDKey.Address() - nodeID := ids.BuildTestNodeID(rewardAddress[:]) + nodeID := ids.BuildTestShortNodeID(rewardAddress[:]) _, err := addPendingValidator( env, @@ -1184,7 +1184,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { builder, txSigner := env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddValidatorTx( &txs.Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), Start: uint64(staker0StartTime.Unix()), End: uint64(staker0EndTime.Unix()), Wght: 10, @@ -1245,7 +1245,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { require.NoError(commitBlk.Accept(context.Background())) // Test validator weight before delegation - vdrWeight := env.config.Validators.GetWeight(constants.PrimaryNetworkID, nodeID) + vdrWeight := env.config.Validators.GetWeight(constants.PrimaryNetworkID, nodeID.NodeID()) require.Equal(env.config.MinValidatorStake, vdrWeight) // Add delegator @@ -1285,7 +1285,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { builder, txSigner = env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err = builder.NewAddValidatorTx( &txs.Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), Start: uint64(staker0StartTime.Unix()), End: uint64(staker0EndTime.Unix()), Wght: 10, @@ -1346,7 +1346,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { require.NoError(commitBlk.Accept(context.Background())) // Test validator weight after delegation - vdrWeight = env.config.Validators.GetWeight(constants.PrimaryNetworkID, nodeID) + vdrWeight = env.config.Validators.GetWeight(constants.PrimaryNetworkID, nodeID.NodeID()) require.Equal(env.config.MinDelegatorStake+env.config.MinValidatorStake, vdrWeight) } @@ -1360,7 +1360,7 @@ func TestAddValidatorProposalBlock(t *testing.T) { var ( validatorStartTime = now.Add(2 * executor.SyncBound) validatorEndTime = validatorStartTime.Add(env.config.MinStakeDuration) - nodeID = ids.GenerateTestNodeID() + nodeID = ids.GenerateTestShortNodeID() ) sk, err := bls.NewSecretKey() @@ -1411,7 +1411,7 @@ func TestAddValidatorProposalBlock(t *testing.T) { require.True(env.blkManager.SetPreference(statelessBlk.ID())) // Should be current - staker, err := env.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID) + staker, err := env.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.NoError(err) require.NotNil(staker) @@ -1446,7 +1446,7 @@ func TestAddValidatorProposalBlock(t *testing.T) { // Create another validator tx validatorStartTime = now.Add(2 * executor.SyncBound) validatorEndTime = validatorStartTime.Add(env.config.MinStakeDuration) - nodeID = ids.GenerateTestNodeID() + nodeID = ids.GenerateTestShortNodeID() sk, err = bls.NewSecretKey() require.NoError(err) @@ -1505,7 +1505,7 @@ func TestAddValidatorProposalBlock(t *testing.T) { require.NoError(commitBlk.Accept(context.Background())) // Should be current - staker, err = env.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID) + staker, err = env.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.NoError(err) require.NotNil(staker) diff --git a/vms/platformvm/block/executor/standard_block_test.go b/vms/platformvm/block/executor/standard_block_test.go index 4d732b72e94e..75a78f1eb38c 100644 --- a/vms/platformvm/block/executor/standard_block_test.go +++ b/vms/platformvm/block/executor/standard_block_test.go @@ -300,7 +300,7 @@ func TestBanffStandardBlockUpdatePrimaryNetworkStakers(t *testing.T) { // Add a pending validator pendingValidatorStartTime := genesistest.DefaultValidatorStartTime.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMinStakingDuration) - nodeID := ids.GenerateTestNodeID() + nodeID := ids.GenerateTestShortNodeID() rewardAddress := ids.GenerateTestShortID() addPendingValidatorTx, err := addPendingValidator( env, @@ -331,17 +331,17 @@ func TestBanffStandardBlockUpdatePrimaryNetworkStakers(t *testing.T) { // tests blkStateMap := env.blkManager.(*manager).blkIDToState updatedState := blkStateMap[block.ID()].onAcceptState - currentValidator, err := updatedState.GetCurrentValidator(constants.PrimaryNetworkID, nodeID) + currentValidator, err := updatedState.GetCurrentValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.NoError(err) require.Equal(addPendingValidatorTx.ID(), currentValidator.TxID) require.Equal(uint64(1370), currentValidator.PotentialReward) // See rewards tests to explain why 1370 - _, err = updatedState.GetPendingValidator(constants.PrimaryNetworkID, nodeID) + _, err = updatedState.GetPendingValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.ErrorIs(err, database.ErrNotFound) // Test VM validators require.NoError(block.Accept(context.Background())) - _, ok := env.config.Validators.GetValidator(constants.PrimaryNetworkID, nodeID) + _, ok := env.config.Validators.GetValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.True(ok) } @@ -363,37 +363,37 @@ func TestBanffStandardBlockUpdateStakers(t *testing.T) { // So in this test we avoid ids.GenerateTestNodeID, in favour of ids.BuildTestNodeID // so that TxID does not depend on the order we run tests. staker1 := staker{ - nodeID: ids.BuildTestNodeID([]byte{0xf1}), + nodeID: ids.BuildTestShortNodeID([]byte{0xf1}), rewardAddress: ids.ShortID{0xf1}, startTime: genesistest.DefaultValidatorStartTime.Add(1 * time.Minute), endTime: genesistest.DefaultValidatorStartTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute), } staker2 := staker{ - nodeID: ids.BuildTestNodeID([]byte{0xf2}), + nodeID: ids.BuildTestShortNodeID([]byte{0xf2}), rewardAddress: ids.ShortID{0xf2}, startTime: staker1.startTime.Add(1 * time.Minute), endTime: staker1.startTime.Add(1 * time.Minute).Add(defaultMinStakingDuration), } staker3 := staker{ - nodeID: ids.BuildTestNodeID([]byte{0xf3}), + nodeID: ids.BuildTestShortNodeID([]byte{0xf3}), rewardAddress: ids.ShortID{0xf3}, startTime: staker2.startTime.Add(1 * time.Minute), endTime: staker2.endTime.Add(1 * time.Minute), } staker3Sub := staker{ - nodeID: ids.BuildTestNodeID([]byte{0xf3}), + nodeID: ids.BuildTestShortNodeID([]byte{0xf3}), rewardAddress: ids.ShortID{0xff}, startTime: staker3.startTime.Add(1 * time.Minute), endTime: staker3.endTime.Add(-1 * time.Minute), } staker4 := staker{ - nodeID: ids.BuildTestNodeID([]byte{0xf4}), + nodeID: ids.BuildTestShortNodeID([]byte{0xf4}), rewardAddress: ids.ShortID{0xf4}, startTime: staker3.startTime, endTime: staker3.endTime, } staker5 := staker{ - nodeID: ids.BuildTestNodeID([]byte{0xf5}), + nodeID: ids.BuildTestShortNodeID([]byte{0xf5}), rewardAddress: ids.ShortID{0xf5}, startTime: staker2.endTime, endTime: staker2.endTime.Add(defaultMinStakingDuration), @@ -405,14 +405,14 @@ func TestBanffStandardBlockUpdateStakers(t *testing.T) { stakers: []staker{staker1, staker2, staker3, staker4, staker5}, subnetStakers: []staker{staker1}, advanceTimeTo: []time.Time{staker1.startTime}, - expectedStakers: map[ids.NodeID]stakerStatus{ + expectedStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: current, staker2.nodeID: pending, staker3.nodeID: pending, staker4.nodeID: pending, staker5.nodeID: pending, }, - expectedSubnetStakers: map[ids.NodeID]stakerStatus{ + expectedSubnetStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: current, staker2.nodeID: pending, staker3.nodeID: pending, @@ -424,7 +424,7 @@ func TestBanffStandardBlockUpdateStakers(t *testing.T) { description: "advance time to the staker2 start", stakers: []staker{staker1, staker2, staker3, staker4, staker5}, advanceTimeTo: []time.Time{staker1.startTime, staker2.startTime}, - expectedStakers: map[ids.NodeID]stakerStatus{ + expectedStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: current, staker2.nodeID: current, staker3.nodeID: pending, @@ -437,14 +437,14 @@ func TestBanffStandardBlockUpdateStakers(t *testing.T) { stakers: []staker{staker1, staker2, staker3, staker4, staker5}, subnetStakers: []staker{staker1, staker2, staker3Sub, staker4, staker5}, advanceTimeTo: []time.Time{staker1.startTime, staker2.startTime, staker3.startTime}, - expectedStakers: map[ids.NodeID]stakerStatus{ + expectedStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: current, staker2.nodeID: current, staker3.nodeID: current, staker4.nodeID: current, staker5.nodeID: pending, }, - expectedSubnetStakers: map[ids.NodeID]stakerStatus{ + expectedSubnetStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: current, staker2.nodeID: current, staker3Sub.nodeID: pending, @@ -457,14 +457,14 @@ func TestBanffStandardBlockUpdateStakers(t *testing.T) { stakers: []staker{staker1, staker2, staker3, staker4, staker5}, subnetStakers: []staker{staker1, staker2, staker3Sub, staker4, staker5}, advanceTimeTo: []time.Time{staker1.startTime, staker2.startTime, staker3.startTime, staker3Sub.startTime}, - expectedStakers: map[ids.NodeID]stakerStatus{ + expectedStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: current, staker2.nodeID: current, staker3.nodeID: current, staker4.nodeID: current, staker5.nodeID: pending, }, - expectedSubnetStakers: map[ids.NodeID]stakerStatus{ + expectedSubnetStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: current, staker2.nodeID: current, staker3.nodeID: current, @@ -476,7 +476,7 @@ func TestBanffStandardBlockUpdateStakers(t *testing.T) { description: "advance time to staker5 start", stakers: []staker{staker1, staker2, staker3, staker4, staker5}, advanceTimeTo: []time.Time{staker1.startTime, staker2.startTime, staker3.startTime, staker5.startTime}, - expectedStakers: map[ids.NodeID]stakerStatus{ + expectedStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: current, // Staker2's end time matches staker5's start time, so typically @@ -566,14 +566,14 @@ func TestBanffStandardBlockUpdateStakers(t *testing.T) { for stakerNodeID, status := range test.expectedStakers { switch status { case pending: - _, err := env.state.GetPendingValidator(constants.PrimaryNetworkID, stakerNodeID) + _, err := env.state.GetPendingValidator(constants.PrimaryNetworkID, stakerNodeID.NodeID()) require.NoError(err) - _, ok := env.config.Validators.GetValidator(constants.PrimaryNetworkID, stakerNodeID) + _, ok := env.config.Validators.GetValidator(constants.PrimaryNetworkID, stakerNodeID.NodeID()) require.False(ok) case current: - _, err := env.state.GetCurrentValidator(constants.PrimaryNetworkID, stakerNodeID) + _, err := env.state.GetCurrentValidator(constants.PrimaryNetworkID, stakerNodeID.NodeID()) require.NoError(err) - _, ok := env.config.Validators.GetValidator(constants.PrimaryNetworkID, stakerNodeID) + _, ok := env.config.Validators.GetValidator(constants.PrimaryNetworkID, stakerNodeID.NodeID()) require.True(ok) } } @@ -581,10 +581,10 @@ func TestBanffStandardBlockUpdateStakers(t *testing.T) { for stakerNodeID, status := range test.expectedSubnetStakers { switch status { case pending: - _, ok := env.config.Validators.GetValidator(subnetID, stakerNodeID) + _, ok := env.config.Validators.GetValidator(subnetID, stakerNodeID.NodeID()) require.False(ok) case current: - _, ok := env.config.Validators.GetValidator(subnetID, stakerNodeID) + _, ok := env.config.Validators.GetValidator(subnetID, stakerNodeID.NodeID()) require.True(ok) } } @@ -610,7 +610,7 @@ func TestBanffStandardBlockRemoveSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: subnetValidatorNodeID.NodeID(), + NodeID: subnetValidatorNodeID, Start: genesistest.DefaultValidatorStartTimeUnix, End: uint64(subnetVdr1EndTime.Unix()), Wght: 1, @@ -642,7 +642,7 @@ func TestBanffStandardBlockRemoveSubnetValidator(t *testing.T) { utx, err = builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: subnetVdr2NodeID.NodeID(), + NodeID: subnetVdr2NodeID, Start: uint64(subnetVdr1EndTime.Add(time.Second).Unix()), End: uint64(subnetVdr1EndTime.Add(time.Second).Add(defaultMinStakingDuration).Unix()), Wght: 1, @@ -716,7 +716,7 @@ func TestBanffStandardBlockTrackedSubnet(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: subnetValidatorNodeID.NodeID(), + NodeID: subnetValidatorNodeID, Start: uint64(subnetVdr1StartTime.Unix()), End: uint64(subnetVdr1EndTime.Unix()), Wght: 1, @@ -771,7 +771,7 @@ func TestBanffStandardBlockDelegatorStakerWeight(t *testing.T) { // Add a pending validator pendingValidatorStartTime := genesistest.DefaultValidatorStartTime.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMaxStakingDuration) - nodeID := ids.GenerateTestNodeID() + nodeID := ids.GenerateTestShortNodeID() rewardAddress := ids.GenerateTestShortID() _, err := addPendingValidator( env, @@ -800,7 +800,7 @@ func TestBanffStandardBlockDelegatorStakerWeight(t *testing.T) { require.NoError(env.state.Commit()) // Test validator weight before delegation - vdrWeight := env.config.Validators.GetWeight(constants.PrimaryNetworkID, nodeID) + vdrWeight := env.config.Validators.GetWeight(constants.PrimaryNetworkID, nodeID.NodeID()) require.Equal(env.config.MinValidatorStake, vdrWeight) // Add delegator @@ -852,6 +852,6 @@ func TestBanffStandardBlockDelegatorStakerWeight(t *testing.T) { require.NoError(env.state.Commit()) // Test validator weight after delegation - vdrWeight = env.config.Validators.GetWeight(constants.PrimaryNetworkID, nodeID) + vdrWeight = env.config.Validators.GetWeight(constants.PrimaryNetworkID, nodeID.NodeID()) require.Equal(env.config.MinDelegatorStake+env.config.MinValidatorStake, vdrWeight) } diff --git a/vms/platformvm/genesis/genesistest/genesis.go b/vms/platformvm/genesis/genesistest/genesis.go index 318a781682ad..b3dfe5d222d9 100644 --- a/vms/platformvm/genesis/genesistest/genesis.go +++ b/vms/platformvm/genesis/genesistest/genesis.go @@ -58,7 +58,7 @@ func init() { } type Config struct { - NodeIDs []ids.NodeID + NodeIDs []ids.ShortNodeID ValidatorWeight uint64 ValidatorStartTime time.Time ValidatorEndTime time.Time @@ -69,9 +69,7 @@ type Config struct { func New(t testing.TB, c Config) *platformvmgenesis.Genesis { if len(c.NodeIDs) == 0 { - for _, shortNodeID := range DefaultNodeIDs { - c.NodeIDs = append(c.NodeIDs, shortNodeID.NodeID()) - } + c.NodeIDs = append(c.NodeIDs, DefaultNodeIDs...) } if c.ValidatorWeight == 0 { c.ValidatorWeight = DefaultValidatorWeight diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index 6513b194af6c..2b209261347e 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -254,7 +254,7 @@ func TestGetTx(t *testing.T) { tx, err := wallet.IssueAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), Start: uint64(s.vm.clock.Time().Add(txexecutor.SyncBound).Unix()), End: uint64(s.vm.clock.Time().Add(txexecutor.SyncBound).Add(defaultMinStakingDuration).Unix()), Wght: s.vm.MinValidatorStake, @@ -507,7 +507,7 @@ func TestGetStake(t *testing.T) { }) tx, err := wallet.IssueAddDelegatorTx( &txs.Validator{ - NodeID: delegatorNodeID.NodeID(), + NodeID: delegatorNodeID, Start: genesistest.DefaultValidatorStartTimeUnix, End: uint64(delegatorEndTime.Unix()), Wght: stakeAmount, @@ -558,7 +558,7 @@ func TestGetStake(t *testing.T) { // Make sure this works for pending stakers // Add a pending staker stakeAmount = service.vm.MinValidatorStake + 54321 - pendingStakerNodeID := ids.GenerateTestNodeID() + pendingStakerNodeID := ids.GenerateTestShortNodeID() pendingStakerEndTime := uint64(genesistest.DefaultValidatorStartTime.Add(defaultMinStakingDuration).Unix()) tx, err = wallet.IssueAddValidatorTx( &txs.Validator{ @@ -645,7 +645,7 @@ func TestGetCurrentValidators(t *testing.T) { wallet := newWallet(t, service.vm, walletConfig{}) delTx, err := wallet.IssueAddDelegatorTx( &txs.Validator{ - NodeID: validatorNodeID.NodeID(), + NodeID: validatorNodeID, Start: genesistest.DefaultValidatorStartTimeUnix, End: uint64(delegatorEndTime.Unix()), Wght: stakeAmount, diff --git a/vms/platformvm/state/disk_staker_diff_iterator.go b/vms/platformvm/state/disk_staker_diff_iterator.go index 690962ae8c96..f114a28d8ac0 100644 --- a/vms/platformvm/state/disk_staker_diff_iterator.go +++ b/vms/platformvm/state/disk_staker_diff_iterator.go @@ -15,7 +15,7 @@ const ( // startDiffKey = [subnetID] + [inverseHeight] startDiffKeyLength = ids.IDLen + database.Uint64Size // diffKey = [subnetID] + [inverseHeight] + [nodeID] - diffKeyLength = startDiffKeyLength + ids.NodeIDLen + diffKeyLength = startDiffKeyLength + ids.ShortNodeIDLen // diffKeyNodeIDOffset = [subnetIDLen] + [inverseHeightLen] diffKeyNodeIDOffset = ids.IDLen + database.Uint64Size diff --git a/vms/platformvm/state/staker_test.go b/vms/platformvm/state/staker_test.go index 91b7b8047508..3f13d32439dc 100644 --- a/vms/platformvm/state/staker_test.go +++ b/vms/platformvm/state/staker_test.go @@ -201,7 +201,7 @@ func TestNewPendingStaker(t *testing.T) { } func generateStakerTx(require *require.Assertions) *txs.AddPermissionlessValidatorTx { - nodeID := ids.GenerateTestNodeID() + nodeID := ids.GenerateTestShortNodeID() sk, err := bls.NewSecretKey() require.NoError(err) pop := signer.NewProofOfPossession(sk) diff --git a/vms/platformvm/state/state_test.go b/vms/platformvm/state/state_test.go index de2bab544c00..0cf01a4c8fc2 100644 --- a/vms/platformvm/state/state_test.go +++ b/vms/platformvm/state/state_test.go @@ -47,13 +47,13 @@ import ( safemath "github.com/ava-labs/avalanchego/utils/math" ) -var defaultValidatorNodeID = ids.GenerateTestNodeID() +var defaultValidatorShortNodeID = ids.GenerateTestShortNodeID() func newTestState(t testing.TB, db database.Database) *state { s, err := New( db, genesistest.NewBytes(t, genesistest.Config{ - NodeIDs: []ids.NodeID{defaultValidatorNodeID}, + NodeIDs: []ids.ShortNodeID{defaultValidatorShortNodeID}, }), prometheus.NewRegistry(), validators.NewManager(), @@ -81,12 +81,12 @@ func TestStateSyncGenesis(t *testing.T) { require := require.New(t) state := newTestState(t, memdb.New()) - staker, err := state.GetCurrentValidator(constants.PrimaryNetworkID, defaultValidatorNodeID) + staker, err := state.GetCurrentValidator(constants.PrimaryNetworkID, defaultValidatorShortNodeID.NodeID()) require.NoError(err) require.NotNil(staker) - require.Equal(defaultValidatorNodeID, staker.NodeID) + require.Equal(defaultValidatorShortNodeID.NodeID(), staker.NodeID) - delegatorIterator, err := state.GetCurrentDelegatorIterator(constants.PrimaryNetworkID, defaultValidatorNodeID) + delegatorIterator, err := state.GetCurrentDelegatorIterator(constants.PrimaryNetworkID, defaultValidatorShortNodeID.NodeID()) require.NoError(err) assertIteratorsEqual(t, iterator.Empty[*Staker]{}, delegatorIterator) @@ -94,10 +94,10 @@ func TestStateSyncGenesis(t *testing.T) { require.NoError(err) assertIteratorsEqual(t, iterator.FromSlice(staker), stakerIterator) - _, err = state.GetPendingValidator(constants.PrimaryNetworkID, defaultValidatorNodeID) + _, err = state.GetPendingValidator(constants.PrimaryNetworkID, defaultValidatorShortNodeID.NodeID()) require.ErrorIs(err, database.ErrNotFound) - delegatorIterator, err = state.GetPendingDelegatorIterator(constants.PrimaryNetworkID, defaultValidatorNodeID) + delegatorIterator, err = state.GetPendingDelegatorIterator(constants.PrimaryNetworkID, defaultValidatorShortNodeID.NodeID()) require.NoError(err) assertIteratorsEqual(t, iterator.Empty[*Staker]{}, delegatorIterator) } @@ -129,7 +129,7 @@ func TestPersistStakers(t *testing.T) { endTime = time.Now().Add(14 * 24 * time.Hour).Unix() validatorsData = txs.Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), End: uint64(endTime), Wght: 1234, } @@ -205,7 +205,7 @@ func TestPersistStakers(t *testing.T) { valEndTime = time.Unix(valStartTime, 0).Add(365 * 24 * time.Hour).Unix() validatorsData = txs.Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), End: uint64(valEndTime), Wght: 1234, } @@ -291,7 +291,7 @@ func TestPersistStakers(t *testing.T) { endTime = time.Now().Add(14 * 24 * time.Hour).Unix() validatorsData = txs.Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), Start: uint64(startTime), End: uint64(endTime), Wght: 1234, @@ -347,7 +347,7 @@ func TestPersistStakers(t *testing.T) { valEndTime = time.Unix(valStartTime, 0).Add(365 * 24 * time.Hour).Unix() validatorsData = txs.Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), Start: uint64(valStartTime), End: uint64(valEndTime), Wght: 1234, @@ -409,7 +409,7 @@ func TestPersistStakers(t *testing.T) { endTime = time.Now().Add(14 * 24 * time.Hour).Unix() validatorsData = txs.Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), End: uint64(endTime), Wght: 1234, } @@ -479,7 +479,7 @@ func TestPersistStakers(t *testing.T) { valEndTime = time.Unix(valStartTime, 0).Add(365 * 24 * time.Hour).Unix() validatorsData = txs.Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), End: uint64(valEndTime), Wght: 1234, } @@ -565,7 +565,7 @@ func TestPersistStakers(t *testing.T) { endTime = time.Now().Add(14 * 24 * time.Hour).Unix() validatorsData = txs.Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), Start: uint64(startTime), End: uint64(endTime), Wght: 1234, @@ -621,7 +621,7 @@ func TestPersistStakers(t *testing.T) { valEndTime = time.Unix(valStartTime, 0).Add(365 * 24 * time.Hour).Unix() validatorsData = txs.Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), Start: uint64(valStartTime), End: uint64(valEndTime), Wght: 1234, diff --git a/vms/platformvm/txs/add_delegator_test.go b/vms/platformvm/txs/add_delegator_test.go index 3d2ba834f9c6..8d77c3874ff5 100644 --- a/vms/platformvm/txs/add_delegator_test.go +++ b/vms/platformvm/txs/add_delegator_test.go @@ -75,6 +75,8 @@ func TestAddDelegatorTxSyntacticVerify(t *testing.T) { }, }, }} + thisNodeID, err := ids.ShortNodeIDFromNodeID(ctx.NodeID) + require.NoError(err) addDelegatorTx = &AddDelegatorTx{ BaseTx: BaseTx{BaseTx: avax.BaseTx{ NetworkID: ctx.NetworkID, @@ -84,7 +86,7 @@ func TestAddDelegatorTxSyntacticVerify(t *testing.T) { Memo: []byte{1, 2, 3, 4, 5, 6, 7, 8}, }}, Validator: Validator{ - NodeID: ctx.NodeID, + NodeID: thisNodeID, Start: uint64(clk.Time().Unix()), End: uint64(clk.Time().Add(time.Hour).Unix()), Wght: validatorWeight, @@ -174,6 +176,8 @@ func TestAddDelegatorTxSyntacticVerifyNotAVAX(t *testing.T) { }, }, }} + thisNodeID, err := ids.ShortNodeIDFromNodeID(ctx.NodeID) + require.NoError(err) addDelegatorTx = &AddDelegatorTx{ BaseTx: BaseTx{BaseTx: avax.BaseTx{ NetworkID: ctx.NetworkID, @@ -183,7 +187,7 @@ func TestAddDelegatorTxSyntacticVerifyNotAVAX(t *testing.T) { Memo: []byte{1, 2, 3, 4, 5, 6, 7, 8}, }}, Validator: Validator{ - NodeID: ctx.NodeID, + NodeID: thisNodeID, Start: uint64(clk.Time().Unix()), End: uint64(clk.Time().Add(time.Hour).Unix()), Wght: validatorWeight, diff --git a/vms/platformvm/txs/add_delegator_tx.go b/vms/platformvm/txs/add_delegator_tx.go index 25e9a9251821..0a96b26dcac6 100644 --- a/vms/platformvm/txs/add_delegator_tx.go +++ b/vms/platformvm/txs/add_delegator_tx.go @@ -55,7 +55,7 @@ func (*AddDelegatorTx) SubnetID() ids.ID { } func (tx *AddDelegatorTx) NodeID() ids.NodeID { - return tx.Validator.NodeID + return tx.Validator.NodeID.NodeID() } func (*AddDelegatorTx) PublicKey() (*bls.PublicKey, bool, error) { diff --git a/vms/platformvm/txs/add_permissionless_delegator_tx.go b/vms/platformvm/txs/add_permissionless_delegator_tx.go index 38fd73e7f857..b06e23bb8409 100644 --- a/vms/platformvm/txs/add_permissionless_delegator_tx.go +++ b/vms/platformvm/txs/add_permissionless_delegator_tx.go @@ -53,7 +53,7 @@ func (tx *AddPermissionlessDelegatorTx) SubnetID() ids.ID { } func (tx *AddPermissionlessDelegatorTx) NodeID() ids.NodeID { - return tx.Validator.NodeID + return tx.Validator.NodeID.NodeID() } func (*AddPermissionlessDelegatorTx) PublicKey() (*bls.PublicKey, bool, error) { diff --git a/vms/platformvm/txs/add_permissionless_delegator_tx_test.go b/vms/platformvm/txs/add_permissionless_delegator_tx_test.go index 7f5625b6e50c..16427515c087 100644 --- a/vms/platformvm/txs/add_permissionless_delegator_tx_test.go +++ b/vms/platformvm/txs/add_permissionless_delegator_tx_test.go @@ -54,7 +54,7 @@ func TestAddPermissionlessPrimaryDelegatorSerialization(t *testing.T) { 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, } - nodeID := ids.BuildTestNodeID([]byte{ + nodeID := ids.BuildTestShortNodeID([]byte{ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x11, 0x22, 0x33, 0x44, @@ -768,7 +768,7 @@ func TestAddPermissionlessSubnetDelegatorSerialization(t *testing.T) { 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, } - nodeID := ids.BuildTestNodeID([]byte{ + nodeID := ids.BuildTestShortNodeID([]byte{ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x11, 0x22, 0x33, 0x44, @@ -1565,7 +1565,7 @@ func TestAddPermissionlessDelegatorTxSyntacticVerify(t *testing.T) { return &AddPermissionlessDelegatorTx{ BaseTx: invalidBaseTx, Validator: Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), }, StakeOuts: []*avax.TransferableOutput{ { @@ -1712,7 +1712,7 @@ func TestAddPermissionlessDelegatorTxSyntacticVerify(t *testing.T) { return &AddPermissionlessDelegatorTx{ BaseTx: validBaseTx, Validator: Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), Wght: 1, }, Subnet: ids.GenerateTestID(), diff --git a/vms/platformvm/txs/add_permissionless_validator_tx.go b/vms/platformvm/txs/add_permissionless_validator_tx.go index 15a11bc23cae..a6889760bf6a 100644 --- a/vms/platformvm/txs/add_permissionless_validator_tx.go +++ b/vms/platformvm/txs/add_permissionless_validator_tx.go @@ -76,7 +76,7 @@ func (tx *AddPermissionlessValidatorTx) SubnetID() ids.ID { } func (tx *AddPermissionlessValidatorTx) NodeID() ids.NodeID { - return tx.Validator.NodeID + return tx.Validator.NodeID.NodeID() } func (tx *AddPermissionlessValidatorTx) PublicKey() (*bls.PublicKey, bool, error) { @@ -124,7 +124,7 @@ func (tx *AddPermissionlessValidatorTx) SyntacticVerify(ctx *snow.Context) error return ErrNilTx case tx.SyntacticallyVerified: // already passed syntactic verification return nil - case tx.Validator.NodeID == ids.EmptyNodeID: + case tx.Validator.NodeID == ids.EmptyShortNodeID: return errEmptyNodeID case len(tx.StakeOuts) == 0: // Ensure there is provided stake return errNoStake diff --git a/vms/platformvm/txs/add_permissionless_validator_tx_test.go b/vms/platformvm/txs/add_permissionless_validator_tx_test.go index 5caa7cd040df..9b18ac585bfe 100644 --- a/vms/platformvm/txs/add_permissionless_validator_tx_test.go +++ b/vms/platformvm/txs/add_permissionless_validator_tx_test.go @@ -60,7 +60,7 @@ func TestAddPermissionlessPrimaryValidator(t *testing.T) { 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, } - nodeID := ids.BuildTestNodeID([]byte{ + nodeID := ids.BuildTestShortNodeID([]byte{ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x11, 0x22, 0x33, 0x44, @@ -725,7 +725,7 @@ func TestAddPermissionlessSubnetValidator(t *testing.T) { 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, } - nodeID := ids.BuildTestNodeID([]byte{ + nodeID := ids.BuildTestShortNodeID([]byte{ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x11, 0x22, 0x33, 0x44, @@ -1428,7 +1428,7 @@ func TestAddPermissionlessValidatorTxSyntacticVerify(t *testing.T) { return &AddPermissionlessValidatorTx{ BaseTx: validBaseTx, Validator: Validator{ - NodeID: ids.EmptyNodeID, + NodeID: ids.EmptyShortNodeID, }, } }, @@ -1440,7 +1440,7 @@ func TestAddPermissionlessValidatorTxSyntacticVerify(t *testing.T) { return &AddPermissionlessValidatorTx{ BaseTx: validBaseTx, Validator: Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), }, StakeOuts: nil, } @@ -1453,7 +1453,7 @@ func TestAddPermissionlessValidatorTxSyntacticVerify(t *testing.T) { return &AddPermissionlessValidatorTx{ BaseTx: validBaseTx, Validator: Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), }, StakeOuts: []*avax.TransferableOutput{ { @@ -1476,7 +1476,7 @@ func TestAddPermissionlessValidatorTxSyntacticVerify(t *testing.T) { return &AddPermissionlessValidatorTx{ BaseTx: invalidBaseTx, Validator: Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), }, StakeOuts: []*avax.TransferableOutput{ { @@ -1501,7 +1501,7 @@ func TestAddPermissionlessValidatorTxSyntacticVerify(t *testing.T) { return &AddPermissionlessValidatorTx{ BaseTx: validBaseTx, Validator: Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), Wght: 1, }, Subnet: ids.GenerateTestID(), @@ -1531,7 +1531,7 @@ func TestAddPermissionlessValidatorTxSyntacticVerify(t *testing.T) { return &AddPermissionlessValidatorTx{ BaseTx: validBaseTx, Validator: Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), Wght: 1, }, Subnet: constants.PrimaryNetworkID, @@ -1564,7 +1564,7 @@ func TestAddPermissionlessValidatorTxSyntacticVerify(t *testing.T) { return &AddPermissionlessValidatorTx{ BaseTx: validBaseTx, Validator: Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), Wght: 1, }, Subnet: ids.GenerateTestID(), @@ -1593,7 +1593,7 @@ func TestAddPermissionlessValidatorTxSyntacticVerify(t *testing.T) { return &AddPermissionlessValidatorTx{ BaseTx: validBaseTx, Validator: Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), Wght: 1, }, Subnet: ids.GenerateTestID(), @@ -1631,7 +1631,7 @@ func TestAddPermissionlessValidatorTxSyntacticVerify(t *testing.T) { return &AddPermissionlessValidatorTx{ BaseTx: validBaseTx, Validator: Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), Wght: 1, }, Subnet: ids.GenerateTestID(), @@ -1670,7 +1670,7 @@ func TestAddPermissionlessValidatorTxSyntacticVerify(t *testing.T) { return &AddPermissionlessValidatorTx{ BaseTx: validBaseTx, Validator: Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), Wght: 1, }, Subnet: ids.GenerateTestID(), @@ -1709,7 +1709,7 @@ func TestAddPermissionlessValidatorTxSyntacticVerify(t *testing.T) { return &AddPermissionlessValidatorTx{ BaseTx: validBaseTx, Validator: Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), Wght: 1, }, Subnet: ids.GenerateTestID(), @@ -1748,7 +1748,7 @@ func TestAddPermissionlessValidatorTxSyntacticVerify(t *testing.T) { return &AddPermissionlessValidatorTx{ BaseTx: validBaseTx, Validator: Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), Wght: 2, }, Subnet: ids.GenerateTestID(), @@ -1787,7 +1787,7 @@ func TestAddPermissionlessValidatorTxSyntacticVerify(t *testing.T) { return &AddPermissionlessValidatorTx{ BaseTx: validBaseTx, Validator: Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), Wght: 2, }, Subnet: constants.PrimaryNetworkID, diff --git a/vms/platformvm/txs/add_subnet_validator_test.go b/vms/platformvm/txs/add_subnet_validator_test.go index b3c3630ef2f0..d7a67007d94d 100644 --- a/vms/platformvm/txs/add_subnet_validator_test.go +++ b/vms/platformvm/txs/add_subnet_validator_test.go @@ -65,6 +65,8 @@ func TestAddSubnetValidatorTxSyntacticVerify(t *testing.T) { subnetAuth := &secp256k1fx.Input{ SigIndices: []uint32{0, 1}, } + thisNodeID, err := ids.ShortNodeIDFromNodeID(ctx.NodeID) + require.NoError(err) addSubnetValidatorTx = &AddSubnetValidatorTx{ BaseTx: BaseTx{BaseTx: avax.BaseTx{ NetworkID: ctx.NetworkID, @@ -75,7 +77,7 @@ func TestAddSubnetValidatorTxSyntacticVerify(t *testing.T) { }}, SubnetValidator: SubnetValidator{ Validator: Validator{ - NodeID: ctx.NodeID, + NodeID: thisNodeID, Start: uint64(clk.Time().Unix()), End: uint64(clk.Time().Add(time.Hour).Unix()), Wght: validatorWeight, @@ -176,6 +178,8 @@ func TestAddSubnetValidatorMarshal(t *testing.T) { subnetAuth := &secp256k1fx.Input{ SigIndices: []uint32{0, 1}, } + thisNodeID, err := ids.ShortNodeIDFromNodeID(ctx.NodeID) + require.NoError(err) addSubnetValidatorTx = &AddSubnetValidatorTx{ BaseTx: BaseTx{BaseTx: avax.BaseTx{ NetworkID: ctx.NetworkID, @@ -186,7 +190,7 @@ func TestAddSubnetValidatorMarshal(t *testing.T) { }}, SubnetValidator: SubnetValidator{ Validator: Validator{ - NodeID: ctx.NodeID, + NodeID: thisNodeID, Start: uint64(clk.Time().Unix()), End: uint64(clk.Time().Add(time.Hour).Unix()), Wght: validatorWeight, diff --git a/vms/platformvm/txs/add_subnet_validator_tx.go b/vms/platformvm/txs/add_subnet_validator_tx.go index b6ce0d0fe4da..2725b8d619d7 100644 --- a/vms/platformvm/txs/add_subnet_validator_tx.go +++ b/vms/platformvm/txs/add_subnet_validator_tx.go @@ -31,7 +31,7 @@ type AddSubnetValidatorTx struct { } func (tx *AddSubnetValidatorTx) NodeID() ids.NodeID { - return tx.SubnetValidator.NodeID + return tx.SubnetValidator.NodeID.NodeID() } func (*AddSubnetValidatorTx) PublicKey() (*bls.PublicKey, bool, error) { diff --git a/vms/platformvm/txs/add_validator_test.go b/vms/platformvm/txs/add_validator_test.go index 27ea18dc5a7e..a76481fedf94 100644 --- a/vms/platformvm/txs/add_validator_test.go +++ b/vms/platformvm/txs/add_validator_test.go @@ -75,6 +75,8 @@ func TestAddValidatorTxSyntacticVerify(t *testing.T) { }, }, }} + thisNodeID, err := ids.ShortNodeIDFromNodeID(ctx.NodeID) + require.NoError(err) addValidatorTx = &AddValidatorTx{ BaseTx: BaseTx{BaseTx: avax.BaseTx{ NetworkID: ctx.NetworkID, @@ -83,7 +85,7 @@ func TestAddValidatorTxSyntacticVerify(t *testing.T) { Outs: outputs, }}, Validator: Validator{ - NodeID: ctx.NodeID, + NodeID: thisNodeID, Start: uint64(clk.Time().Unix()), End: uint64(clk.Time().Add(time.Hour).Unix()), Wght: validatorWeight, @@ -191,6 +193,8 @@ func TestAddValidatorTxSyntacticVerifyNotAVAX(t *testing.T) { }, }, }} + thisNodeID, err := ids.ShortNodeIDFromNodeID(ctx.NodeID) + require.NoError(err) addValidatorTx = &AddValidatorTx{ BaseTx: BaseTx{BaseTx: avax.BaseTx{ NetworkID: ctx.NetworkID, @@ -199,7 +203,7 @@ func TestAddValidatorTxSyntacticVerifyNotAVAX(t *testing.T) { Outs: outputs, }}, Validator: Validator{ - NodeID: ctx.NodeID, + NodeID: thisNodeID, Start: uint64(clk.Time().Unix()), End: uint64(clk.Time().Add(time.Hour).Unix()), Wght: validatorWeight, diff --git a/vms/platformvm/txs/add_validator_tx.go b/vms/platformvm/txs/add_validator_tx.go index 8a86ef172713..81b5e8545067 100644 --- a/vms/platformvm/txs/add_validator_tx.go +++ b/vms/platformvm/txs/add_validator_tx.go @@ -58,7 +58,7 @@ func (*AddValidatorTx) SubnetID() ids.ID { } func (tx *AddValidatorTx) NodeID() ids.NodeID { - return tx.Validator.NodeID + return tx.Validator.NodeID.NodeID() } func (*AddValidatorTx) PublicKey() (*bls.PublicKey, bool, error) { diff --git a/vms/platformvm/txs/executor/advance_time_test.go b/vms/platformvm/txs/executor/advance_time_test.go index f4a3ed99e7ca..f46144da2cb3 100644 --- a/vms/platformvm/txs/executor/advance_time_test.go +++ b/vms/platformvm/txs/executor/advance_time_test.go @@ -49,7 +49,7 @@ func TestAdvanceTimeTxUpdatePrimaryNetworkStakers(t *testing.T) { // Add a pending validator pendingValidatorStartTime := genesistest.DefaultValidatorStartTime.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMinStakingDuration) - nodeID := ids.GenerateTestNodeID() + nodeID := ids.GenerateTestShortNodeID() addPendingValidatorTx, err := addPendingValidator( env, pendingValidatorStartTime, @@ -78,18 +78,18 @@ func TestAdvanceTimeTxUpdatePrimaryNetworkStakers(t *testing.T) { } require.NoError(tx.Unsigned.Visit(&executor)) - validatorStaker, err := executor.OnCommitState.GetCurrentValidator(constants.PrimaryNetworkID, nodeID) + validatorStaker, err := executor.OnCommitState.GetCurrentValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.NoError(err) require.Equal(addPendingValidatorTx.ID(), validatorStaker.TxID) require.Equal(uint64(1370), validatorStaker.PotentialReward) // See rewards tests to explain why 1370 - _, err = executor.OnCommitState.GetPendingValidator(constants.PrimaryNetworkID, nodeID) + _, err = executor.OnCommitState.GetPendingValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.ErrorIs(err, database.ErrNotFound) - _, err = executor.OnAbortState.GetCurrentValidator(constants.PrimaryNetworkID, nodeID) + _, err = executor.OnAbortState.GetCurrentValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.ErrorIs(err, database.ErrNotFound) - validatorStaker, err = executor.OnAbortState.GetPendingValidator(constants.PrimaryNetworkID, nodeID) + validatorStaker, err = executor.OnAbortState.GetPendingValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.NoError(err) require.Equal(addPendingValidatorTx.ID(), validatorStaker.TxID) @@ -98,7 +98,7 @@ func TestAdvanceTimeTxUpdatePrimaryNetworkStakers(t *testing.T) { env.state.SetHeight(dummyHeight) require.NoError(env.state.Commit()) - _, ok := env.config.Validators.GetValidator(constants.PrimaryNetworkID, nodeID) + _, ok := env.config.Validators.GetValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.True(ok) } @@ -139,7 +139,7 @@ func TestAdvanceTimeTxTimestampTooLate(t *testing.T) { // Add a pending validator pendingValidatorStartTime := genesistest.DefaultValidatorStartTime.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMinStakingDuration) - nodeID := ids.GenerateTestNodeID() + nodeID := ids.GenerateTestShortNodeID() _, err := addPendingValidator(env, pendingValidatorStartTime, pendingValidatorEndTime, nodeID, []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}) require.NoError(err) @@ -208,7 +208,7 @@ func TestAdvanceTimeTxUpdateStakers(t *testing.T) { ) type staker struct { - nodeID ids.NodeID + nodeID ids.ShortNodeID startTime, endTime time.Time } type test struct { @@ -216,8 +216,8 @@ func TestAdvanceTimeTxUpdateStakers(t *testing.T) { stakers []staker subnetStakers []staker advanceTimeTo []time.Time - expectedStakers map[ids.NodeID]stakerStatus - expectedSubnetStakers map[ids.NodeID]stakerStatus + expectedStakers map[ids.ShortNodeID]stakerStatus + expectedSubnetStakers map[ids.ShortNodeID]stakerStatus } // Chronological order (not in scale): @@ -228,17 +228,17 @@ func TestAdvanceTimeTxUpdateStakers(t *testing.T) { // Staker4: |------------------------| // Staker5: |--------------------| staker1 := staker{ - nodeID: ids.GenerateTestNodeID(), + nodeID: ids.GenerateTestShortNodeID(), startTime: genesistest.DefaultValidatorStartTime.Add(1 * time.Minute), endTime: genesistest.DefaultValidatorStartTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute), } staker2 := staker{ - nodeID: ids.GenerateTestNodeID(), + nodeID: ids.GenerateTestShortNodeID(), startTime: staker1.startTime.Add(1 * time.Minute), endTime: staker1.startTime.Add(1 * time.Minute).Add(defaultMinStakingDuration), } staker3 := staker{ - nodeID: ids.GenerateTestNodeID(), + nodeID: ids.GenerateTestShortNodeID(), startTime: staker2.startTime.Add(1 * time.Minute), endTime: staker2.endTime.Add(1 * time.Minute), } @@ -248,12 +248,12 @@ func TestAdvanceTimeTxUpdateStakers(t *testing.T) { endTime: staker3.endTime.Add(-1 * time.Minute), } staker4 := staker{ - nodeID: ids.GenerateTestNodeID(), + nodeID: ids.GenerateTestShortNodeID(), startTime: staker3.startTime, endTime: staker3.endTime, } staker5 := staker{ - nodeID: ids.GenerateTestNodeID(), + nodeID: ids.GenerateTestShortNodeID(), startTime: staker2.endTime, endTime: staker2.endTime.Add(defaultMinStakingDuration), } @@ -264,14 +264,14 @@ func TestAdvanceTimeTxUpdateStakers(t *testing.T) { stakers: []staker{staker1, staker2, staker3, staker4, staker5}, subnetStakers: []staker{staker1, staker2, staker3, staker4, staker5}, advanceTimeTo: []time.Time{staker1.startTime.Add(-1 * time.Second)}, - expectedStakers: map[ids.NodeID]stakerStatus{ + expectedStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: pending, staker2.nodeID: pending, staker3.nodeID: pending, staker4.nodeID: pending, staker5.nodeID: pending, }, - expectedSubnetStakers: map[ids.NodeID]stakerStatus{ + expectedSubnetStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: pending, staker2.nodeID: pending, staker3.nodeID: pending, @@ -284,14 +284,14 @@ func TestAdvanceTimeTxUpdateStakers(t *testing.T) { stakers: []staker{staker1, staker2, staker3, staker4, staker5}, subnetStakers: []staker{staker1}, advanceTimeTo: []time.Time{staker1.startTime}, - expectedStakers: map[ids.NodeID]stakerStatus{ + expectedStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: current, staker2.nodeID: pending, staker3.nodeID: pending, staker4.nodeID: pending, staker5.nodeID: pending, }, - expectedSubnetStakers: map[ids.NodeID]stakerStatus{ + expectedSubnetStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: current, staker2.nodeID: pending, staker3.nodeID: pending, @@ -303,7 +303,7 @@ func TestAdvanceTimeTxUpdateStakers(t *testing.T) { description: "advance time to the staker2 start", stakers: []staker{staker1, staker2, staker3, staker4, staker5}, advanceTimeTo: []time.Time{staker1.startTime, staker2.startTime}, - expectedStakers: map[ids.NodeID]stakerStatus{ + expectedStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: current, staker2.nodeID: current, staker3.nodeID: pending, @@ -316,14 +316,14 @@ func TestAdvanceTimeTxUpdateStakers(t *testing.T) { stakers: []staker{staker1, staker2, staker3, staker4, staker5}, subnetStakers: []staker{staker1, staker2, staker3Sub, staker4, staker5}, advanceTimeTo: []time.Time{staker1.startTime, staker2.startTime, staker3.startTime}, - expectedStakers: map[ids.NodeID]stakerStatus{ + expectedStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: current, staker2.nodeID: current, staker3.nodeID: current, staker4.nodeID: current, staker5.nodeID: pending, }, - expectedSubnetStakers: map[ids.NodeID]stakerStatus{ + expectedSubnetStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: current, staker2.nodeID: current, staker3Sub.nodeID: pending, @@ -336,14 +336,14 @@ func TestAdvanceTimeTxUpdateStakers(t *testing.T) { stakers: []staker{staker1, staker2, staker3, staker4, staker5}, subnetStakers: []staker{staker1, staker2, staker3Sub, staker4, staker5}, advanceTimeTo: []time.Time{staker1.startTime, staker2.startTime, staker3.startTime, staker3Sub.startTime}, - expectedStakers: map[ids.NodeID]stakerStatus{ + expectedStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: current, staker2.nodeID: current, staker3.nodeID: current, staker4.nodeID: current, staker5.nodeID: pending, }, - expectedSubnetStakers: map[ids.NodeID]stakerStatus{ + expectedSubnetStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: current, staker2.nodeID: current, staker3.nodeID: current, @@ -355,7 +355,7 @@ func TestAdvanceTimeTxUpdateStakers(t *testing.T) { description: "advance time to staker5 end", stakers: []staker{staker1, staker2, staker3, staker4, staker5}, advanceTimeTo: []time.Time{staker1.startTime, staker2.startTime, staker3.startTime, staker5.startTime}, - expectedStakers: map[ids.NodeID]stakerStatus{ + expectedStakers: map[ids.ShortNodeID]stakerStatus{ staker1.nodeID: current, staker2.nodeID: current, staker3.nodeID: current, @@ -446,14 +446,14 @@ func TestAdvanceTimeTxUpdateStakers(t *testing.T) { for stakerNodeID, status := range test.expectedStakers { switch status { case pending: - _, err := env.state.GetPendingValidator(constants.PrimaryNetworkID, stakerNodeID) + _, err := env.state.GetPendingValidator(constants.PrimaryNetworkID, stakerNodeID.NodeID()) require.NoError(err) - _, ok := env.config.Validators.GetValidator(constants.PrimaryNetworkID, stakerNodeID) + _, ok := env.config.Validators.GetValidator(constants.PrimaryNetworkID, stakerNodeID.NodeID()) require.False(ok) case current: - _, err := env.state.GetCurrentValidator(constants.PrimaryNetworkID, stakerNodeID) + _, err := env.state.GetCurrentValidator(constants.PrimaryNetworkID, stakerNodeID.NodeID()) require.NoError(err) - _, ok := env.config.Validators.GetValidator(constants.PrimaryNetworkID, stakerNodeID) + _, ok := env.config.Validators.GetValidator(constants.PrimaryNetworkID, stakerNodeID.NodeID()) require.True(ok) } } @@ -461,10 +461,10 @@ func TestAdvanceTimeTxUpdateStakers(t *testing.T) { for stakerNodeID, status := range test.expectedSubnetStakers { switch status { case pending: - _, ok := env.config.Validators.GetValidator(subnetID, stakerNodeID) + _, ok := env.config.Validators.GetValidator(subnetID, stakerNodeID.NodeID()) require.False(ok) case current: - _, ok := env.config.Validators.GetValidator(subnetID, stakerNodeID) + _, ok := env.config.Validators.GetValidator(subnetID, stakerNodeID.NodeID()) require.True(ok) } } @@ -494,7 +494,7 @@ func TestAdvanceTimeTxRemoveSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: subnetValidatorNodeID.NodeID(), + NodeID: subnetValidatorNodeID, Start: genesistest.DefaultValidatorStartTimeUnix, End: uint64(subnetVdr1EndTime.Unix()), Wght: 1, @@ -527,7 +527,7 @@ func TestAdvanceTimeTxRemoveSubnetValidator(t *testing.T) { utx, err = builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: subnetVdr2NodeID.NodeID(), + NodeID: subnetVdr2NodeID, Start: uint64(subnetVdr1EndTime.Add(time.Second).Unix()), End: uint64(subnetVdr1EndTime.Add(time.Second).Add(defaultMinStakingDuration).Unix()), Wght: 1, @@ -610,7 +610,7 @@ func TestTrackedSubnet(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: subnetValidatorNodeID.NodeID(), + NodeID: subnetValidatorNodeID, Start: uint64(subnetVdr1StartTime.Unix()), End: uint64(subnetVdr1EndTime.Unix()), Wght: 1, @@ -675,7 +675,7 @@ func TestAdvanceTimeTxDelegatorStakerWeight(t *testing.T) { // Add a pending validator pendingValidatorStartTime := genesistest.DefaultValidatorStartTime.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMaxStakingDuration) - nodeID := ids.GenerateTestNodeID() + nodeID := ids.GenerateTestShortNodeID() _, err := addPendingValidator( env, pendingValidatorStartTime, @@ -710,7 +710,7 @@ func TestAdvanceTimeTxDelegatorStakerWeight(t *testing.T) { require.NoError(env.state.Commit()) // Test validator weight before delegation - vdrWeight := env.config.Validators.GetWeight(constants.PrimaryNetworkID, nodeID) + vdrWeight := env.config.Validators.GetWeight(constants.PrimaryNetworkID, nodeID.NodeID()) require.Equal(env.config.MinValidatorStake, vdrWeight) // Add delegator @@ -770,7 +770,7 @@ func TestAdvanceTimeTxDelegatorStakerWeight(t *testing.T) { require.NoError(env.state.Commit()) // Test validator weight after delegation - vdrWeight = env.config.Validators.GetWeight(constants.PrimaryNetworkID, nodeID) + vdrWeight = env.config.Validators.GetWeight(constants.PrimaryNetworkID, nodeID.NodeID()) require.Equal(env.config.MinDelegatorStake+env.config.MinValidatorStake, vdrWeight) } @@ -785,7 +785,7 @@ func TestAdvanceTimeTxDelegatorStakers(t *testing.T) { // Add a pending validator pendingValidatorStartTime := genesistest.DefaultValidatorStartTime.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMinStakingDuration) - nodeID := ids.GenerateTestNodeID() + nodeID := ids.GenerateTestShortNodeID() _, err := addPendingValidator(env, pendingValidatorStartTime, pendingValidatorEndTime, nodeID, []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}) require.NoError(err) @@ -814,7 +814,7 @@ func TestAdvanceTimeTxDelegatorStakers(t *testing.T) { require.NoError(env.state.Commit()) // Test validator weight before delegation - vdrWeight := env.config.Validators.GetWeight(constants.PrimaryNetworkID, nodeID) + vdrWeight := env.config.Validators.GetWeight(constants.PrimaryNetworkID, nodeID.NodeID()) require.Equal(env.config.MinValidatorStake, vdrWeight) // Add delegator @@ -873,7 +873,7 @@ func TestAdvanceTimeTxDelegatorStakers(t *testing.T) { require.NoError(env.state.Commit()) // Test validator weight after delegation - vdrWeight = env.config.Validators.GetWeight(constants.PrimaryNetworkID, nodeID) + vdrWeight = env.config.Validators.GetWeight(constants.PrimaryNetworkID, nodeID.NodeID()) require.Equal(env.config.MinDelegatorStake+env.config.MinValidatorStake, vdrWeight) } @@ -938,13 +938,13 @@ func addPendingValidator( env *environment, startTime time.Time, endTime time.Time, - nodeID ids.NodeID, + nodeShortID ids.ShortNodeID, keys []*secp256k1.PrivateKey, ) (*txs.Tx, error) { builder, signer := env.factory.NewWallet(keys...) utx, err := builder.NewAddValidatorTx( &txs.Validator{ - NodeID: nodeID, + NodeID: nodeShortID, Start: uint64(startTime.Unix()), End: uint64(endTime.Unix()), Wght: env.config.MinValidatorStake, diff --git a/vms/platformvm/txs/executor/proposal_tx_executor_test.go b/vms/platformvm/txs/executor/proposal_tx_executor_test.go index 15a1bee2893d..c15f7583a56a 100644 --- a/vms/platformvm/txs/executor/proposal_tx_executor_test.go +++ b/vms/platformvm/txs/executor/proposal_tx_executor_test.go @@ -31,7 +31,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { rewardAddress := genesistest.DefaultFundedKeys[0].Address() nodeID := genesistest.DefaultNodeIDs[0] - newValidatorID := ids.GenerateTestNodeID() + newValidatorID := ids.GenerateTestShortNodeID() newValidatorStartTime := uint64(genesistest.DefaultValidatorStartTime.Add(5 * time.Second).Unix()) newValidatorEndTime := uint64(genesistest.DefaultValidatorEndTime.Add(-5 * time.Second).Unix()) @@ -119,7 +119,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { stakeAmount uint64 startTime uint64 endTime uint64 - nodeID ids.NodeID + nodeID ids.ShortNodeID feeKeys []*secp256k1.PrivateKey setup func(*environment) AP3Time time.Time @@ -132,7 +132,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { stakeAmount: env.config.MinDelegatorStake, startTime: genesistest.DefaultValidatorStartTimeUnix + 1, endTime: genesistest.DefaultValidatorEndTimeUnix + 1, - nodeID: nodeID.NodeID(), + nodeID: nodeID, feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: nil, AP3Time: genesistest.DefaultValidatorStartTime, @@ -187,7 +187,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { stakeAmount: env.config.MinDelegatorStake, startTime: uint64(currentTimestamp.Unix()), endTime: genesistest.DefaultValidatorEndTimeUnix, - nodeID: nodeID.NodeID(), + nodeID: nodeID, feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: nil, AP3Time: genesistest.DefaultValidatorStartTime, @@ -198,7 +198,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { stakeAmount: env.config.MinDelegatorStake, startTime: genesistest.DefaultValidatorStartTimeUnix + 1, endTime: genesistest.DefaultValidatorEndTimeUnix, - nodeID: nodeID.NodeID(), + nodeID: nodeID, feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[1]}, setup: func(env *environment) { // Remove all UTXOs owned by keys[1] utxoIDs, err := env.state.UTXOIDs( @@ -302,7 +302,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: shortNodeID.NodeID(), + NodeID: shortNodeID, Start: genesistest.DefaultValidatorStartTimeUnix + 1, End: genesistest.DefaultValidatorEndTimeUnix + 1, Wght: genesistest.DefaultValidatorWeight, @@ -341,7 +341,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: shortNodeID.NodeID(), + NodeID: shortNodeID, Start: genesistest.DefaultValidatorStartTimeUnix + 1, End: genesistest.DefaultValidatorEndTimeUnix, Wght: genesistest.DefaultValidatorWeight, @@ -372,7 +372,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { // Add a validator to pending validator set of primary network // Starts validating primary network 10 seconds after genesis - pendingDSValidatorID := ids.GenerateTestNodeID() + pendingDSValidatorID := ids.GenerateTestShortNodeID() dsStartTime := genesistest.DefaultValidatorStartTime.Add(10 * time.Second) dsEndTime := dsStartTime.Add(5 * defaultMinStakingDuration) @@ -567,7 +567,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: shortNodeID.NodeID(), + NodeID: shortNodeID, Start: uint64(newTimestamp.Unix()), End: uint64(newTimestamp.Add(defaultMinStakingDuration).Unix()), Wght: genesistest.DefaultValidatorWeight, @@ -606,7 +606,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { uSubnetTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: shortNodeID.NodeID(), + NodeID: shortNodeID, Start: genesistest.DefaultValidatorStartTimeUnix, End: genesistest.DefaultValidatorEndTimeUnix, Wght: genesistest.DefaultValidatorWeight, @@ -638,7 +638,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: shortNodeID.NodeID(), + NodeID: shortNodeID, Start: genesistest.DefaultValidatorStartTimeUnix + 1, End: genesistest.DefaultValidatorEndTimeUnix, Wght: genesistest.DefaultValidatorWeight, @@ -678,7 +678,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: shortNodeID.NodeID(), + NodeID: shortNodeID, Start: genesistest.DefaultValidatorStartTimeUnix + 1, End: uint64(genesistest.DefaultValidatorStartTime.Add(defaultMinStakingDuration).Unix()) + 1, Wght: genesistest.DefaultValidatorWeight, @@ -721,7 +721,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: shortNodeID.NodeID(), + NodeID: shortNodeID, Start: genesistest.DefaultValidatorStartTimeUnix + 1, End: uint64(genesistest.DefaultValidatorStartTime.Add(defaultMinStakingDuration).Unix()) + 1, Wght: genesistest.DefaultValidatorWeight, @@ -763,7 +763,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: shortNodeID.NodeID(), + NodeID: shortNodeID, Start: genesistest.DefaultValidatorStartTimeUnix + 1, End: uint64(genesistest.DefaultValidatorStartTime.Add(defaultMinStakingDuration).Unix()) + 1, Wght: genesistest.DefaultValidatorWeight, @@ -814,7 +814,7 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - nodeID := ids.GenerateTestNodeID() + nodeID := ids.GenerateTestShortNodeID() chainTime := env.state.GetTimestamp() { @@ -862,7 +862,7 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ - NodeID: shortNodeID.NodeID(), + NodeID: shortNodeID, Start: genesistest.DefaultValidatorStartTimeUnix + 1, End: genesistest.DefaultValidatorEndTimeUnix, Wght: env.config.MinValidatorStake, @@ -954,7 +954,7 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), Start: genesistest.DefaultValidatorStartTimeUnix + 1, End: genesistest.DefaultValidatorEndTimeUnix, Wght: env.config.MinValidatorStake, diff --git a/vms/platformvm/txs/executor/reward_validator_test.go b/vms/platformvm/txs/executor/reward_validator_test.go index 27dd9d304937..3ba95959e41e 100644 --- a/vms/platformvm/txs/executor/reward_validator_test.go +++ b/vms/platformvm/txs/executor/reward_validator_test.go @@ -249,7 +249,7 @@ func TestRewardDelegatorTxExecuteOnCommitPreDelegateeDeferral(t *testing.T) { vdrStartTime := genesistest.DefaultValidatorStartTimeUnix + 1 vdrEndTime := uint64(genesistest.DefaultValidatorStartTime.Add(2 * defaultMinStakingDuration).Unix()) - vdrNodeID := ids.GenerateTestNodeID() + vdrNodeID := ids.GenerateTestShortNodeID() builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) uVdrTx, err := builder.NewAddValidatorTx( @@ -315,7 +315,7 @@ func TestRewardDelegatorTxExecuteOnCommitPreDelegateeDeferral(t *testing.T) { require.NoError(env.state.Commit()) // test validator stake - stake := env.config.Validators.GetWeight(constants.PrimaryNetworkID, vdrNodeID) + stake := env.config.Validators.GetWeight(constants.PrimaryNetworkID, vdrNodeID.NodeID()) require.Equal(env.config.MinValidatorStake+env.config.MinDelegatorStake, stake) tx, err := newRewardValidatorTx(t, delTx.ID()) @@ -369,7 +369,7 @@ func TestRewardDelegatorTxExecuteOnCommitPreDelegateeDeferral(t *testing.T) { require.Less(vdrReward, delReward, "the delegator's reward should be greater than the delegatee's because the delegatee's share is 25%") require.Equal(expectedReward, delReward+vdrReward, "expected total reward to be %d but is %d", expectedReward, delReward+vdrReward) - stake = env.config.Validators.GetWeight(constants.PrimaryNetworkID, vdrNodeID) + stake = env.config.Validators.GetWeight(constants.PrimaryNetworkID, vdrNodeID.NodeID()) require.Equal(env.config.MinValidatorStake, stake) } @@ -383,7 +383,7 @@ func TestRewardDelegatorTxExecuteOnCommitPostDelegateeDeferral(t *testing.T) { vdrStartTime := genesistest.DefaultValidatorStartTimeUnix + 1 vdrEndTime := uint64(genesistest.DefaultValidatorStartTime.Add(2 * defaultMinStakingDuration).Unix()) - vdrNodeID := ids.GenerateTestNodeID() + vdrNodeID := ids.GenerateTestShortNodeID() builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) uVdrTx, err := builder.NewAddValidatorTx( @@ -459,7 +459,7 @@ func TestRewardDelegatorTxExecuteOnCommitPostDelegateeDeferral(t *testing.T) { require.NoError(err) // test validator stake - stake := env.config.Validators.GetWeight(constants.PrimaryNetworkID, vdrNodeID) + stake := env.config.Validators.GetWeight(constants.PrimaryNetworkID, vdrNodeID.NodeID()) require.Equal(env.config.MinValidatorStake+env.config.MinDelegatorStake, stake) tx, err := newRewardValidatorTx(t, delTx.ID()) @@ -613,7 +613,7 @@ func TestRewardDelegatorTxAndValidatorTxExecuteOnCommitPostDelegateeDeferral(t * vdrStartTime := genesistest.DefaultValidatorStartTimeUnix + 1 vdrEndTime := uint64(genesistest.DefaultValidatorStartTime.Add(2 * defaultMinStakingDuration).Unix()) - vdrNodeID := ids.GenerateTestNodeID() + vdrNodeID := ids.GenerateTestShortNodeID() builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) uVdrTx, err := builder.NewAddValidatorTx( @@ -789,7 +789,7 @@ func TestRewardDelegatorTxExecuteOnAbort(t *testing.T) { vdrStartTime := genesistest.DefaultValidatorStartTimeUnix + 1 vdrEndTime := uint64(genesistest.DefaultValidatorStartTime.Add(2 * defaultMinStakingDuration).Unix()) - vdrNodeID := ids.GenerateTestNodeID() + vdrNodeID := ids.GenerateTestShortNodeID() builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) uVdrTx, err := builder.NewAddValidatorTx( diff --git a/vms/platformvm/txs/executor/staker_tx_verification.go b/vms/platformvm/txs/executor/staker_tx_verification.go index d458c01ab259..7bec531242ad 100644 --- a/vms/platformvm/txs/executor/staker_tx_verification.go +++ b/vms/platformvm/txs/executor/staker_tx_verification.go @@ -52,7 +52,7 @@ func verifySubnetValidatorPrimaryNetworkRequirements( chainState state.Chain, subnetValidator txs.Validator, ) error { - primaryNetworkValidator, err := GetValidator(chainState, constants.PrimaryNetworkID, subnetValidator.NodeID) + primaryNetworkValidator, err := GetValidator(chainState, constants.PrimaryNetworkID, subnetValidator.NodeID.NodeID()) if err == database.ErrNotFound { return fmt.Errorf( "%s %w of the primary network", @@ -149,7 +149,7 @@ func verifyAddValidatorTx( return nil, err } - _, err := GetValidator(chainState, constants.PrimaryNetworkID, tx.Validator.NodeID) + _, err := GetValidator(chainState, constants.PrimaryNetworkID, tx.Validator.NodeID.NodeID()) if err == nil { return nil, fmt.Errorf( "%s is %w of the primary network", @@ -232,7 +232,7 @@ func verifyAddSubnetValidatorTx( return err } - _, err := GetValidator(chainState, tx.SubnetValidator.Subnet, tx.Validator.NodeID) + _, err := GetValidator(chainState, tx.SubnetValidator.Subnet, tx.Validator.NodeID.NodeID()) if err == nil { return fmt.Errorf( "attempted to issue %w for %s on subnet %s", @@ -318,9 +318,9 @@ func verifyRemoveSubnetValidatorTx( } isCurrentValidator := true - vdr, err := chainState.GetCurrentValidator(tx.Subnet, tx.NodeID) + vdr, err := chainState.GetCurrentValidator(tx.Subnet, tx.NodeID.NodeID()) if err == database.ErrNotFound { - vdr, err = chainState.GetPendingValidator(tx.Subnet, tx.NodeID) + vdr, err = chainState.GetPendingValidator(tx.Subnet, tx.NodeID.NodeID()) isCurrentValidator = false } if err != nil { @@ -427,7 +427,7 @@ func verifyAddDelegatorTx( return nil, err } - primaryNetworkValidator, err := GetValidator(chainState, constants.PrimaryNetworkID, tx.Validator.NodeID) + primaryNetworkValidator, err := GetValidator(chainState, constants.PrimaryNetworkID, tx.Validator.NodeID.NodeID()) if err != nil { return nil, fmt.Errorf( "failed to fetch the primary network validator for %s: %w", @@ -562,7 +562,7 @@ func verifyAddPermissionlessValidatorTx( ) } - _, err = GetValidator(chainState, tx.Subnet, tx.Validator.NodeID) + _, err = GetValidator(chainState, tx.Subnet, tx.Validator.NodeID.NodeID()) if err == nil { return fmt.Errorf( "%w: %s on %s", @@ -679,7 +679,7 @@ func verifyAddPermissionlessDelegatorTx( ) } - validator, err := GetValidator(chainState, tx.Subnet, tx.Validator.NodeID) + validator, err := GetValidator(chainState, tx.Subnet, tx.Validator.NodeID.NodeID()) if err != nil { return fmt.Errorf( "failed to fetch the validator for %s on %s: %w", diff --git a/vms/platformvm/txs/executor/staker_tx_verification_test.go b/vms/platformvm/txs/executor/staker_tx_verification_test.go index 037d789a8eb2..4bb39cb8da46 100644 --- a/vms/platformvm/txs/executor/staker_tx_verification_test.go +++ b/vms/platformvm/txs/executor/staker_tx_verification_test.go @@ -75,7 +75,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { }, }, Validator: txs.Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), // Note: [Start] is not set here as it will be ignored // Post-Durango in favor of the current chain time End: uint64(endTime.Unix()), diff --git a/vms/platformvm/txs/executor/standard_tx_executor.go b/vms/platformvm/txs/executor/standard_tx_executor.go index 1204b7d82502..2d4197a6778e 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor.go +++ b/vms/platformvm/txs/executor/standard_tx_executor.go @@ -326,7 +326,7 @@ func (e *StandardTxExecutor) ExportTx(tx *txs.ExportTx) error { } func (e *StandardTxExecutor) AddValidatorTx(tx *txs.AddValidatorTx) error { - if tx.Validator.NodeID == ids.EmptyNodeID { + if tx.Validator.NodeID == ids.EmptyShortNodeID { return errEmptyNodeID } @@ -348,7 +348,7 @@ func (e *StandardTxExecutor) AddValidatorTx(tx *txs.AddValidatorTx) error { avax.Consume(e.State, tx.Ins) avax.Produce(e.State, txID, tx.Outs) - if e.Config.PartialSyncPrimaryNetwork && tx.Validator.NodeID == e.Ctx.NodeID { + if e.Config.PartialSyncPrimaryNetwork && tx.Validator.NodeID.NodeID() == e.Ctx.NodeID { e.Ctx.Log.Warn("verified transaction that would cause this node to become unhealthy", zap.String("reason", "primary network is not being fully synced"), zap.Stringer("txID", txID), @@ -515,7 +515,7 @@ func (e *StandardTxExecutor) AddPermissionlessValidatorTx(tx *txs.AddPermissionl if e.Config.PartialSyncPrimaryNetwork && tx.Subnet == constants.PrimaryNetworkID && - tx.Validator.NodeID == e.Ctx.NodeID { + tx.Validator.NodeID.NodeID() == e.Ctx.NodeID { e.Ctx.Log.Warn("verified transaction that would cause this node to become unhealthy", zap.String("reason", "primary network is not being fully synced"), zap.Stringer("txID", txID), diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index 3c3fcf6358f8..dd2cfcdf463d 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -80,7 +80,7 @@ func TestStandardTxExecutorAddValidatorTxEmptyID(t *testing.T) { builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ - NodeID: ids.EmptyNodeID, + NodeID: ids.EmptyShortNodeID, Start: uint64(startTime.Unix()), End: genesistest.DefaultValidatorEndTimeUnix, Wght: env.config.MinValidatorStake, @@ -115,7 +115,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { rewardAddress := genesistest.DefaultFundedKeys[0].Address() nodeID := genesistest.DefaultNodeIDs[0] - newValidatorID := ids.GenerateTestNodeID() + newValidatorID := ids.GenerateTestShortNodeID() newValidatorStartTime := genesistest.DefaultValidatorStartTime.Add(5 * time.Second) newValidatorEndTime := genesistest.DefaultValidatorEndTime.Add(-5 * time.Second) @@ -203,7 +203,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { stakeAmount uint64 startTime time.Time endTime time.Time - nodeID ids.NodeID + nodeID ids.ShortNodeID feeKeys []*secp256k1.PrivateKey setup func(*environment) AP3Time time.Time @@ -216,7 +216,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { stakeAmount: env.config.MinDelegatorStake, startTime: genesistest.DefaultValidatorStartTime.Add(time.Second), endTime: genesistest.DefaultValidatorEndTime.Add(time.Second), - nodeID: nodeID.NodeID(), + nodeID: nodeID, feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: nil, AP3Time: genesistest.DefaultValidatorStartTime, @@ -271,7 +271,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { stakeAmount: env.config.MinDelegatorStake, // weight startTime: currentTimestamp, // start time endTime: genesistest.DefaultValidatorEndTime, // end time - nodeID: nodeID.NodeID(), // node ID + nodeID: nodeID, // node ID feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, // tx fee payer setup: nil, AP3Time: genesistest.DefaultValidatorStartTime, @@ -282,7 +282,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { stakeAmount: env.config.MinDelegatorStake, // weight startTime: genesistest.DefaultValidatorStartTime.Add(time.Second), // start time endTime: genesistest.DefaultValidatorEndTime, // end time - nodeID: nodeID.NodeID(), // node ID + nodeID: nodeID, // node ID feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[1]}, // tx fee payer setup: func(env *environment) { // Remove all UTXOs owned by keys[1] utxoIDs, err := env.state.UTXOIDs( @@ -386,7 +386,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: shortNodeID.NodeID(), + NodeID: shortNodeID, Start: uint64(startTime.Unix()), End: genesistest.DefaultValidatorEndTimeUnix + 1, Wght: genesistest.DefaultValidatorWeight, @@ -421,7 +421,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: shortNodeID.NodeID(), + NodeID: shortNodeID, Start: genesistest.DefaultValidatorStartTimeUnix + 1, End: genesistest.DefaultValidatorEndTimeUnix, Wght: genesistest.DefaultValidatorWeight, @@ -448,7 +448,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { // Add a validator to pending validator set of primary network // Starts validating primary network 10 seconds after genesis - pendingDSValidatorID := ids.GenerateTestNodeID() + pendingDSValidatorID := ids.GenerateTestShortNodeID() dsStartTime := genesistest.DefaultValidatorStartTime.Add(10 * time.Second) dsEndTime := dsStartTime.Add(5 * defaultMinStakingDuration) @@ -627,7 +627,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: shortNodeID.NodeID(), + NodeID: shortNodeID, Start: uint64(newTimestamp.Unix()), End: uint64(newTimestamp.Add(defaultMinStakingDuration).Unix()), Wght: genesistest.DefaultValidatorWeight, @@ -662,7 +662,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { uSubnetTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: shortNodeID.NodeID(), + NodeID: shortNodeID, Start: genesistest.DefaultValidatorStartTimeUnix, End: genesistest.DefaultValidatorEndTimeUnix, Wght: genesistest.DefaultValidatorWeight, @@ -695,7 +695,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: shortNodeID.NodeID(), + NodeID: shortNodeID, Start: uint64(startTime.Unix()), End: genesistest.DefaultValidatorEndTimeUnix, Wght: genesistest.DefaultValidatorWeight, @@ -732,7 +732,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: shortNodeID.NodeID(), + NodeID: shortNodeID, Start: uint64(startTime.Unix()), End: uint64(startTime.Add(defaultMinStakingDuration).Unix()) + 1, Wght: genesistest.DefaultValidatorWeight, @@ -772,7 +772,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: shortNodeID.NodeID(), + NodeID: shortNodeID, Start: uint64(startTime.Unix()), End: uint64(startTime.Add(defaultMinStakingDuration).Unix()), Wght: genesistest.DefaultValidatorWeight, @@ -812,7 +812,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: shortNodeID.NodeID(), + NodeID: shortNodeID, Start: uint64(startTime.Unix()), End: uint64(startTime.Add(defaultMinStakingDuration).Unix()), Wght: genesistest.DefaultValidatorWeight, @@ -851,7 +851,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: shortNodeID.NodeID(), + NodeID: shortNodeID, Start: uint64(startTime.Unix()) + 1, End: uint64(startTime.Add(defaultMinStakingDuration).Unix()) + 1, Wght: genesistest.DefaultValidatorWeight, @@ -904,7 +904,7 @@ func TestEtnaStandardTxExecutorAddSubnetValidator(t *testing.T) { utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: shortNodeID.NodeID(), + NodeID: shortNodeID, Start: genesistest.DefaultValidatorStartTimeUnix + 1, End: genesistest.DefaultValidatorEndTimeUnix, Wght: genesistest.DefaultValidatorWeight, @@ -936,7 +936,7 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - nodeID := ids.GenerateTestNodeID() + nodeID := ids.GenerateTestShortNodeID() { // Case: Validator's start time too early @@ -1120,7 +1120,7 @@ func TestDurangoDisabledTransactions(t *testing.T) { name: "AddValidatorTx", buildTx: func(env *environment) *txs.Tx { var ( - nodeID = ids.GenerateTestNodeID() + nodeID = ids.GenerateTestShortNodeID() chainTime = env.state.GetTimestamp() endTime = chainTime.Add(defaultMaxStakingDuration) ) @@ -1163,10 +1163,13 @@ func TestDurangoDisabledTransactions(t *testing.T) { } it.Release() + primaryValidatorShortNodeID, err := ids.ShortNodeIDFromNodeID(primaryValidator.NodeID) + require.NoError(t, err) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys...) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ - NodeID: primaryValidator.NodeID, + NodeID: primaryValidatorShortNodeID, Start: 0, End: uint64(primaryValidator.EndTime.Unix()), Wght: defaultMinValidatorStake, @@ -1235,11 +1238,14 @@ func TestDurangoMemoField(t *testing.T) { } it.Release() + primaryValidatorShortNodeID, err := ids.ShortNodeIDFromNodeID(primaryValidator.NodeID) + require.NoError(t, err) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys...) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: primaryValidator.NodeID, + NodeID: primaryValidatorShortNodeID, Start: 0, End: uint64(primaryValidator.EndTime.Unix()), Wght: defaultMinValidatorStake, @@ -1389,12 +1395,15 @@ func TestDurangoMemoField(t *testing.T) { } it.Release() + primaryValidatorShortNodeID, err := ids.ShortNodeIDFromNodeID(primaryValidator.NodeID) + require.NoError(t, err) + endTime := primaryValidator.EndTime builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: primaryValidator.NodeID, + NodeID: primaryValidatorShortNodeID, Start: 0, End: uint64(endTime.Unix()), Wght: genesistest.DefaultValidatorWeight, @@ -1419,7 +1428,7 @@ func TestDurangoMemoField(t *testing.T) { builder, signer = env.factory.NewWallet(genesistest.DefaultFundedKeys...) utx2, err := builder.NewRemoveSubnetValidatorTx( - primaryValidator.NodeID, + primaryValidatorShortNodeID, testSubnet1.ID(), common.WithMemo(memoField), ) @@ -1465,7 +1474,7 @@ func TestDurangoMemoField(t *testing.T) { name: "AddPermissionlessValidatorTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { var ( - nodeID = ids.GenerateTestNodeID() + nodeID = ids.GenerateTestShortNodeID() chainTime = env.state.GetTimestamp() endTime = chainTime.Add(defaultMaxStakingDuration) ) @@ -1522,11 +1531,14 @@ func TestDurangoMemoField(t *testing.T) { } it.Release() + primaryValidatorShortNodeID, err := ids.ShortNodeIDFromNodeID(primaryValidator.NodeID) + require.NoError(t, err) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys...) utx, err := builder.NewAddPermissionlessDelegatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: primaryValidator.NodeID, + NodeID: primaryValidatorShortNodeID, Start: 0, End: uint64(primaryValidator.EndTime.Unix()), Wght: defaultMinValidatorStake, @@ -1705,7 +1717,7 @@ func newRemoveSubnetValidatorTx(t *testing.T) (*txs.RemoveSubnetValidatorTx, *tx }, }, Subnet: ids.GenerateTestID(), - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), SubnetAuth: &secp256k1fx.Credential{ Sigs: make([][65]byte, 1), }, diff --git a/vms/platformvm/txs/fee/complexity.go b/vms/platformvm/txs/fee/complexity.go index 4b06417b8462..c0c7b61a54f9 100644 --- a/vms/platformvm/txs/fee/complexity.go +++ b/vms/platformvm/txs/fee/complexity.go @@ -23,7 +23,7 @@ import ( ) const ( - intrinsicValidatorBandwidth = ids.NodeIDLen + // nodeID + intrinsicValidatorBandwidth = ids.ShortNodeIDLen + // nodeID wrappers.LongLen + // start wrappers.LongLen + // end wrappers.LongLen // weight @@ -157,7 +157,7 @@ var ( } IntrinsicRemoveSubnetValidatorTxComplexities = gas.Dimensions{ gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] + - ids.NodeIDLen + // nodeID + ids.ShortNodeIDLen + // nodeID ids.IDLen + // subnetID wrappers.IntLen + // subnetAuth typeID wrappers.IntLen, // subnetAuthCredential typeID diff --git a/vms/platformvm/txs/remove_subnet_validator_tx.go b/vms/platformvm/txs/remove_subnet_validator_tx.go index ef55cccea290..2b5b4c280400 100644 --- a/vms/platformvm/txs/remove_subnet_validator_tx.go +++ b/vms/platformvm/txs/remove_subnet_validator_tx.go @@ -22,7 +22,7 @@ var ( type RemoveSubnetValidatorTx struct { BaseTx `serialize:"true"` // The node to remove from the subnet. - NodeID ids.NodeID `serialize:"true" json:"nodeID"` + NodeID ids.ShortNodeID `serialize:"true" json:"nodeID"` // The subnet to remove the node from. Subnet ids.ID `serialize:"true" json:"subnetID"` // Proves that the issuer has the right to remove the node from the subnet. diff --git a/vms/platformvm/txs/remove_subnet_validator_tx_test.go b/vms/platformvm/txs/remove_subnet_validator_tx_test.go index 605190977957..6e3e149f5244 100644 --- a/vms/platformvm/txs/remove_subnet_validator_tx_test.go +++ b/vms/platformvm/txs/remove_subnet_validator_tx_test.go @@ -50,7 +50,7 @@ func TestRemoveSubnetValidatorTxSerialization(t *testing.T) { 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, } - nodeID := ids.BuildTestNodeID([]byte{ + nodeID := ids.BuildTestShortNodeID([]byte{ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x11, 0x22, 0x33, 0x44, @@ -575,7 +575,7 @@ func TestRemoveSubnetValidatorTxSyntacticVerify(t *testing.T) { // Set subnetID so we don't error on that check. Subnet: ids.GenerateTestID(), // Set NodeID so we don't error on that check. - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), BaseTx: invalidBaseTx, } }, @@ -587,7 +587,7 @@ func TestRemoveSubnetValidatorTxSyntacticVerify(t *testing.T) { return &RemoveSubnetValidatorTx{ BaseTx: validBaseTx, // Set NodeID so we don't error on that check. - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), Subnet: constants.PrimaryNetworkID, } }, @@ -603,7 +603,7 @@ func TestRemoveSubnetValidatorTxSyntacticVerify(t *testing.T) { // Set subnetID so we don't error on that check. Subnet: ids.GenerateTestID(), // Set NodeID so we don't error on that check. - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), BaseTx: validBaseTx, SubnetAuth: invalidSubnetAuth, } @@ -620,7 +620,7 @@ func TestRemoveSubnetValidatorTxSyntacticVerify(t *testing.T) { // Set subnetID so we don't error on that check. Subnet: ids.GenerateTestID(), // Set NodeID so we don't error on that check. - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), BaseTx: validBaseTx, SubnetAuth: validSubnetAuth, } diff --git a/vms/platformvm/txs/txheap/by_end_time_test.go b/vms/platformvm/txs/txheap/by_end_time_test.go index a629b7b1c3bd..eb091c990478 100644 --- a/vms/platformvm/txs/txheap/by_end_time_test.go +++ b/vms/platformvm/txs/txheap/by_end_time_test.go @@ -23,7 +23,7 @@ func TestByEndTime(t *testing.T) { utx0 := &txs.AddValidatorTx{ Validator: txs.Validator{ - NodeID: ids.BuildTestNodeID([]byte{0}), + NodeID: ids.BuildTestShortNodeID([]byte{0}), Start: uint64(baseTime.Unix()), End: uint64(baseTime.Unix()) + 1, }, @@ -34,7 +34,7 @@ func TestByEndTime(t *testing.T) { utx1 := &txs.AddValidatorTx{ Validator: txs.Validator{ - NodeID: ids.BuildTestNodeID([]byte{1}), + NodeID: ids.BuildTestShortNodeID([]byte{1}), Start: uint64(baseTime.Unix()), End: uint64(baseTime.Unix()) + 2, }, @@ -45,7 +45,7 @@ func TestByEndTime(t *testing.T) { utx2 := &txs.AddValidatorTx{ Validator: txs.Validator{ - NodeID: ids.BuildTestNodeID([]byte{1}), + NodeID: ids.BuildTestShortNodeID([]byte{1}), Start: uint64(baseTime.Unix()), End: uint64(baseTime.Unix()) + 3, }, diff --git a/vms/platformvm/txs/validator.go b/vms/platformvm/txs/validator.go index 726ba23b1c5d..75e8e6ab88b9 100644 --- a/vms/platformvm/txs/validator.go +++ b/vms/platformvm/txs/validator.go @@ -18,7 +18,7 @@ var ( // Validator is a validator. type Validator struct { // Node ID of the validator - NodeID ids.NodeID `serialize:"true" json:"nodeID"` + NodeID ids.ShortNodeID `serialize:"true" json:"nodeID"` // Unix time this validator starts validating Start uint64 `serialize:"true" json:"start"` diff --git a/vms/platformvm/txs/validator_test.go b/vms/platformvm/txs/validator_test.go index 0b9e749ca009..35c489bd9294 100644 --- a/vms/platformvm/txs/validator_test.go +++ b/vms/platformvm/txs/validator_test.go @@ -16,7 +16,7 @@ const defaultWeight = 10000 func TestBoundedBy(t *testing.T) { require := require.New(t) - nodeID := ids.GenerateTestNodeID() + nodeID := ids.GenerateTestShortNodeID() // case 1: a starts, a finishes, b starts, b finishes aStartTime := uint64(0) diff --git a/vms/platformvm/validator_set_property_test.go b/vms/platformvm/validator_set_property_test.go index 6bb693686084..1c735588e15e 100644 --- a/vms/platformvm/validator_set_property_test.go +++ b/vms/platformvm/validator_set_property_test.go @@ -82,7 +82,7 @@ func TestGetValidatorsSetProperty(t *testing.T) { _ = vm.Shutdown(context.Background()) vm.ctx.Lock.Unlock() }() - nodeID := ids.GenerateTestNodeID() + nodeID := ids.GenerateTestShortNodeID() currentTime := genesistest.DefaultValidatorStartTime vm.clock.Set(currentTime) @@ -402,13 +402,13 @@ type validatorInputData struct { eventType uint8 startTime time.Time endTime time.Time - nodeID ids.NodeID + nodeID ids.ShortNodeID publicKey *bls.PublicKey } // buildTimestampsList creates validators start and end time, given the event list. // output is returned as a list of validatorInputData -func buildTimestampsList(events []uint8, currentTime time.Time, nodeID ids.NodeID) ([]*validatorInputData, error) { +func buildTimestampsList(events []uint8, currentTime time.Time, nodeID ids.ShortNodeID) ([]*validatorInputData, error) { res := make([]*validatorInputData, 0, len(events)) currentTime = currentTime.Add(txexecutor.SyncBound) @@ -478,7 +478,7 @@ func TestTimestampListGenerator(t *testing.T) { properties.Property("primary validators are returned in sequence", prop.ForAll( func(events []uint8) string { currentTime := time.Now() - nodeID := ids.GenerateTestNodeID() + nodeID := ids.GenerateTestShortNodeID() validatorsTimes, err := buildTimestampsList(events, currentTime, nodeID) if err != nil { return failedBuildingEventSeqString + err.Error() @@ -529,7 +529,7 @@ func TestTimestampListGenerator(t *testing.T) { properties.Property("subnet validators are returned in sequence", prop.ForAll( func(events []uint8) string { currentTime := time.Now() - nodeID := ids.GenerateTestNodeID() + nodeID := ids.GenerateTestShortNodeID() validatorsTimes, err := buildTimestampsList(events, currentTime, nodeID) if err != nil { return failedBuildingEventSeqString + err.Error() @@ -580,7 +580,7 @@ func TestTimestampListGenerator(t *testing.T) { properties.Property("subnet validators' times are bound by a primary validator's times", prop.ForAll( func(events []uint8) string { currentTime := time.Now() - nodeID := ids.GenerateTestNodeID() + nodeID := ids.GenerateTestShortNodeID() validatorsTimes, err := buildTimestampsList(events, currentTime, nodeID) if err != nil { return failedBuildingEventSeqString + err.Error() @@ -664,8 +664,8 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) { ctx, chainDB, genesistest.NewBytes(t, genesistest.Config{ - NodeIDs: []ids.NodeID{ - genesistest.DefaultNodeIDs[len(genesistest.DefaultNodeIDs)-1].NodeID(), + NodeIDs: []ids.ShortNodeID{ + genesistest.DefaultNodeIDs[len(genesistest.DefaultNodeIDs)-1], }, ValidatorEndTime: mockable.MaxTime, }), diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index 3c562fdd6204..94c9772f2cf1 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -59,7 +59,7 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { validatorStartTime := vm.clock.Time().Add(executor.SyncBound).Add(1 * time.Second) validatorEndTime := validatorStartTime.Add(360 * 24 * time.Hour) - nodeID := ids.GenerateTestNodeID() + nodeID := ids.GenerateTestShortNodeID() rewardsOwner := &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{ids.GenerateTestShortID()}, @@ -211,7 +211,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { wallet := newWallet(t, vm, walletConfig{}) - nodeID := ids.GenerateTestNodeID() + nodeID := ids.GenerateTestShortNodeID() rewardsOwner := &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{ids.GenerateTestShortID()}, @@ -467,7 +467,7 @@ func TestRejectedStateRegressionInvalidValidatorTimestamp(t *testing.T) { wallet := newWallet(t, vm, walletConfig{}) - nodeID := ids.GenerateTestNodeID() + nodeID := ids.GenerateTestShortNodeID() newValidatorStartTime := vm.clock.Time().Add(executor.SyncBound).Add(1 * time.Second) newValidatorEndTime := newValidatorStartTime.Add(defaultMinStakingDuration) @@ -510,7 +510,7 @@ func TestRejectedStateRegressionInvalidValidatorTimestamp(t *testing.T) { onAccept, found := vm.manager.GetState(addValidatorStandardBlk.ID()) require.True(found) - _, err := onAccept.GetPendingValidator(constants.PrimaryNetworkID, nodeID) + _, err := onAccept.GetPendingValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.NoError(err) } @@ -640,10 +640,10 @@ func TestRejectedStateRegressionInvalidValidatorTimestamp(t *testing.T) { // Verify that new validator is now in the current validator set. { - _, err := newState.GetCurrentValidator(constants.PrimaryNetworkID, nodeID) + _, err := newState.GetCurrentValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.NoError(err) - _, err = newState.GetPendingValidator(constants.PrimaryNetworkID, nodeID) + _, err = newState.GetPendingValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.ErrorIs(err, database.ErrNotFound) currentTimestamp := newState.GetTimestamp() @@ -662,7 +662,7 @@ func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) { wallet := newWallet(t, vm, walletConfig{}) - nodeID0 := ids.GenerateTestNodeID() + nodeID0 := ids.GenerateTestShortNodeID() newValidatorStartTime0 := vm.clock.Time().Add(executor.SyncBound).Add(1 * time.Second) newValidatorEndTime0 := newValidatorStartTime0.Add(defaultMaxStakingDuration) @@ -707,7 +707,7 @@ func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) { onAccept, ok := vm.manager.GetState(addValidatorStandardBlk0.ID()) require.True(ok) - _, err := onAccept.GetPendingValidator(constants.PrimaryNetworkID, nodeID0) + _, err := onAccept.GetPendingValidator(constants.PrimaryNetworkID, nodeID0.NodeID()) require.NoError(err) } @@ -736,10 +736,10 @@ func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) { onAccept, ok := vm.manager.GetState(advanceTimeStandardBlk0.ID()) require.True(ok) - _, err := onAccept.GetCurrentValidator(constants.PrimaryNetworkID, nodeID0) + _, err := onAccept.GetCurrentValidator(constants.PrimaryNetworkID, nodeID0.NodeID()) require.NoError(err) - _, err = onAccept.GetPendingValidator(constants.PrimaryNetworkID, nodeID0) + _, err = onAccept.GetPendingValidator(constants.PrimaryNetworkID, nodeID0.NodeID()) require.ErrorIs(err, database.ErrNotFound) currentTimestamp := onAccept.GetTimestamp() @@ -832,7 +832,7 @@ func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) { newValidatorStartTime1 := newValidatorStartTime0.Add(executor.SyncBound).Add(1 * time.Second) newValidatorEndTime1 := newValidatorStartTime1.Add(defaultMaxStakingDuration) - nodeID1 := ids.GenerateTestNodeID() + nodeID1 := ids.GenerateTestShortNodeID() // Create the tx to add the second new validator addValidatorTx1, err := wallet.IssueAddValidatorTx( @@ -869,7 +869,7 @@ func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) { onAccept, ok := vm.manager.GetState(addValidatorStandardBlk1.ID()) require.True(ok) - _, err := onAccept.GetPendingValidator(constants.PrimaryNetworkID, nodeID1) + _, err := onAccept.GetPendingValidator(constants.PrimaryNetworkID, nodeID1.NodeID()) require.NoError(err) } @@ -898,10 +898,10 @@ func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) { onAccept, ok := vm.manager.GetState(advanceTimeStandardBlk1.ID()) require.True(ok) - _, err := onAccept.GetCurrentValidator(constants.PrimaryNetworkID, nodeID1) + _, err := onAccept.GetCurrentValidator(constants.PrimaryNetworkID, nodeID1.NodeID()) require.NoError(err) - _, err = onAccept.GetPendingValidator(constants.PrimaryNetworkID, nodeID1) + _, err = onAccept.GetPendingValidator(constants.PrimaryNetworkID, nodeID1.NodeID()) require.ErrorIs(err, database.ErrNotFound) currentTimestamp := onAccept.GetTimestamp() @@ -933,18 +933,18 @@ func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) { // Verify that validators are in the current validator set with the correct // reward calculated. { - staker0, err := newState.GetCurrentValidator(constants.PrimaryNetworkID, nodeID0) + staker0, err := newState.GetCurrentValidator(constants.PrimaryNetworkID, nodeID0.NodeID()) require.NoError(err) require.Equal(uint64(60000000), staker0.PotentialReward) - staker1, err := newState.GetCurrentValidator(constants.PrimaryNetworkID, nodeID1) + staker1, err := newState.GetCurrentValidator(constants.PrimaryNetworkID, nodeID1.NodeID()) require.NoError(err) require.Equal(uint64(59999999), staker1.PotentialReward) - _, err = newState.GetPendingValidator(constants.PrimaryNetworkID, nodeID0) + _, err = newState.GetPendingValidator(constants.PrimaryNetworkID, nodeID0.NodeID()) require.ErrorIs(err, database.ErrNotFound) - _, err = newState.GetPendingValidator(constants.PrimaryNetworkID, nodeID1) + _, err = newState.GetPendingValidator(constants.PrimaryNetworkID, nodeID1.NodeID()) require.ErrorIs(err, database.ErrNotFound) currentTimestamp := newState.GetTimestamp() @@ -986,7 +986,7 @@ func TestValidatorSetAtCacheOverwriteRegression(t *testing.T) { // Create the tx to add the first new validator addValidatorTx0, err := wallet.IssueAddValidatorTx( &txs.Validator{ - NodeID: extraShortNodeID.NodeID(), + NodeID: extraShortNodeID, Start: uint64(newValidatorStartTime0.Unix()), End: uint64(newValidatorEndTime0.Unix()), Wght: vm.MaxValidatorStake, @@ -1102,7 +1102,7 @@ func TestAddDelegatorTxAddBeforeRemove(t *testing.T) { wallet := newWallet(t, vm, walletConfig{}) - nodeID := ids.GenerateTestNodeID() + nodeID := ids.GenerateTestShortNodeID() rewardsOwner := &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{ids.GenerateTestShortID()}, @@ -1181,7 +1181,7 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionNotTracked(t wallet := newWallet(t, vm, walletConfig{}) - nodeID := ids.GenerateTestNodeID() + nodeID := ids.GenerateTestShortNodeID() addValidatorTx, err := wallet.IssueAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1289,7 +1289,7 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionTracked(t *t wallet := newWallet(t, vm, walletConfig{}) - nodeID := ids.GenerateTestNodeID() + nodeID := ids.GenerateTestShortNodeID() addValidatorTx, err := wallet.IssueAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1392,7 +1392,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { // insert primary network validator var ( - nodeID = ids.GenerateTestNodeID() + nodeID = ids.GenerateTestShortNodeID() rewardsOwner = &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{ids.GenerateTestShortID()}, @@ -1430,7 +1430,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { vm.clock.Set(primaryStartTime) require.NoError(buildAndAcceptStandardBlock(vm)) - _, err = vm.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID) + _, err = vm.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.NoError(err) primaryStartHeight, err := vm.GetCurrentHeight(context.Background()) @@ -1459,7 +1459,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { vm.clock.Set(subnetStartTime) require.NoError(buildAndAcceptStandardBlock(vm)) - _, err = vm.state.GetCurrentValidator(subnetID, nodeID) + _, err = vm.state.GetCurrentValidator(subnetID, nodeID.NodeID()) require.NoError(err) subnetStartHeight, err := vm.GetCurrentHeight(context.Background()) @@ -1469,7 +1469,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { vm.clock.Set(subnetEndTime) require.NoError(buildAndAcceptStandardBlock(vm)) - _, err = vm.state.GetCurrentValidator(subnetID, nodeID) + _, err = vm.state.GetCurrentValidator(subnetID, nodeID.NodeID()) require.ErrorIs(err, database.ErrNotFound) subnetEndHeight, err := vm.GetCurrentHeight(context.Background()) @@ -1493,7 +1493,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { require.NoError(commit.Accept(context.Background())) require.NoError(vm.SetPreference(context.Background(), vm.manager.LastAccepted())) - _, err = vm.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID) + _, err = vm.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.ErrorIs(err, database.ErrNotFound) primaryEndHeight, err := vm.GetCurrentHeight(context.Background()) @@ -1531,7 +1531,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { vm.clock.Set(primaryReStartTime) require.NoError(buildAndAcceptStandardBlock(vm)) - _, err = vm.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID) + _, err = vm.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.NoError(err) primaryRestartHeight, err := vm.GetCurrentHeight(context.Background()) @@ -1541,7 +1541,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { for height := primaryStartHeight; height < primaryEndHeight; height++ { require.NoError(checkValidatorBlsKeyIsSet( vm.State, - nodeID, + nodeID.NodeID(), constants.PrimaryNetworkID, height, pk1, @@ -1550,7 +1550,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { for height := primaryEndHeight; height < primaryRestartHeight; height++ { err := checkValidatorBlsKeyIsSet( vm.State, - nodeID, + nodeID.NodeID(), constants.PrimaryNetworkID, primaryEndHeight, pk1, @@ -1559,7 +1559,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { } require.NoError(checkValidatorBlsKeyIsSet( vm.State, - nodeID, + nodeID.NodeID(), constants.PrimaryNetworkID, primaryRestartHeight, pk2, @@ -1568,7 +1568,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { for height := subnetStartHeight; height < subnetEndHeight; height++ { require.NoError(checkValidatorBlsKeyIsSet( vm.State, - nodeID, + nodeID.NodeID(), subnetID, height, pk1, @@ -1578,7 +1578,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { for height := subnetEndHeight; height <= primaryRestartHeight; height++ { err := checkValidatorBlsKeyIsSet( vm.State, - nodeID, + nodeID.NodeID(), subnetID, primaryEndHeight, pk1, @@ -1609,7 +1609,7 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { ) // Add a primary network validator with no BLS key - nodeID := ids.GenerateTestNodeID() + nodeID := ids.GenerateTestShortNodeID() rewardsOwner := &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{ids.GenerateTestShortID()}, @@ -1636,7 +1636,7 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { vm.clock.Set(primaryStartTime1) require.NoError(buildAndAcceptStandardBlock(vm)) - _, err = vm.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID) + _, err = vm.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.NoError(err) primaryStartHeight, err := vm.GetCurrentHeight(context.Background()) @@ -1660,7 +1660,7 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { require.NoError(commit.Accept(context.Background())) require.NoError(vm.SetPreference(context.Background(), vm.manager.LastAccepted())) - _, err = vm.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID) + _, err = vm.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.ErrorIs(err, database.ErrNotFound) primaryEndHeight, err := vm.GetCurrentHeight(context.Background()) @@ -1697,13 +1697,13 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { vm.clock.Set(primaryStartTime2) require.NoError(buildAndAcceptStandardBlock(vm)) - _, err = vm.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID) + _, err = vm.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.NoError(err) for height := primaryStartHeight; height < primaryEndHeight; height++ { require.NoError(checkValidatorBlsKeyIsSet( vm.State, - nodeID, + nodeID.NodeID(), constants.PrimaryNetworkID, height, nil, @@ -1739,7 +1739,7 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { ) // Add a primary network validator with no BLS key - nodeID := ids.GenerateTestNodeID() + nodeID := ids.GenerateTestShortNodeID() rewardsOwner := &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{ids.GenerateTestShortID()}, @@ -1766,7 +1766,7 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { vm.clock.Set(primaryStartTime1) require.NoError(buildAndAcceptStandardBlock(vm)) - _, err = vm.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID) + _, err = vm.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.NoError(err) primaryStartHeight, err := vm.GetCurrentHeight(context.Background()) @@ -1795,7 +1795,7 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { vm.clock.Set(subnetStartTime) require.NoError(buildAndAcceptStandardBlock(vm)) - _, err = vm.state.GetCurrentValidator(subnetID, nodeID) + _, err = vm.state.GetCurrentValidator(subnetID, nodeID.NodeID()) require.NoError(err) subnetStartHeight, err := vm.GetCurrentHeight(context.Background()) @@ -1805,7 +1805,7 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { vm.clock.Set(subnetEndTime) require.NoError(buildAndAcceptStandardBlock(vm)) - _, err = vm.state.GetCurrentValidator(subnetID, nodeID) + _, err = vm.state.GetCurrentValidator(subnetID, nodeID.NodeID()) require.ErrorIs(err, database.ErrNotFound) subnetEndHeight, err := vm.GetCurrentHeight(context.Background()) @@ -1829,7 +1829,7 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { require.NoError(commit.Accept(context.Background())) require.NoError(vm.SetPreference(context.Background(), vm.manager.LastAccepted())) - _, err = vm.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID) + _, err = vm.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.ErrorIs(err, database.ErrNotFound) primaryEndHeight, err := vm.GetCurrentHeight(context.Background()) @@ -1866,13 +1866,13 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { vm.clock.Set(primaryStartTime2) require.NoError(buildAndAcceptStandardBlock(vm)) - _, err = vm.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID) + _, err = vm.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.NoError(err) for height := primaryStartHeight; height < primaryEndHeight; height++ { require.NoError(checkValidatorBlsKeyIsSet( vm.State, - nodeID, + nodeID.NodeID(), constants.PrimaryNetworkID, height, nil, @@ -1881,7 +1881,7 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { for height := subnetStartHeight; height < subnetEndHeight; height++ { require.NoError(checkValidatorBlsKeyIsSet( vm.State, - nodeID, + nodeID.NodeID(), subnetID, height, nil, @@ -1915,7 +1915,7 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) { ) // Add a primary network validator with no BLS key - nodeID := ids.GenerateTestNodeID() + nodeID := ids.GenerateTestShortNodeID() primaryTx1, err := wallet.IssueAddValidatorTx( &txs.Validator{ @@ -1941,7 +1941,7 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) { vm.clock.Set(primaryStartTime1) require.NoError(buildAndAcceptStandardBlock(vm)) - _, err = vm.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID) + _, err = vm.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.NoError(err) // insert the subnet validator @@ -1967,7 +1967,7 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) { vm.clock.Set(subnetStartTime) require.NoError(buildAndAcceptStandardBlock(vm)) - _, err = vm.state.GetCurrentValidator(subnetID, nodeID) + _, err = vm.state.GetCurrentValidator(subnetID, nodeID.NodeID()) require.NoError(err) subnetStartHeight, err := vm.GetCurrentHeight(context.Background()) @@ -1977,7 +1977,7 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) { vm.clock.Set(subnetEndTime) require.NoError(buildAndAcceptStandardBlock(vm)) - _, err = vm.state.GetCurrentValidator(subnetID, nodeID) + _, err = vm.state.GetCurrentValidator(subnetID, nodeID.NodeID()) require.ErrorIs(err, database.ErrNotFound) // move time ahead, terminating primary network validator @@ -1998,7 +1998,7 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) { require.NoError(commit.Accept(context.Background())) require.NoError(vm.SetPreference(context.Background(), vm.manager.LastAccepted())) - _, err = vm.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID) + _, err = vm.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.ErrorIs(err, database.ErrNotFound) // Generating the validator set should not error when re-introducing a diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 2ebf4aff631f..264276c3fca9 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -303,7 +303,7 @@ func TestAddValidatorCommit(t *testing.T) { var ( endTime = vm.clock.Time().Add(defaultMinStakingDuration) - nodeID = ids.GenerateTestNodeID() + nodeID = ids.GenerateTestShortNodeID() rewardsOwner = &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{ids.GenerateTestShortID()}, @@ -342,7 +342,7 @@ func TestAddValidatorCommit(t *testing.T) { require.Equal(status.Committed, txStatus) // Verify that new validator now in current validator set - _, err = vm.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID) + _, err = vm.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.NoError(err) } @@ -355,7 +355,7 @@ func TestInvalidAddValidatorCommit(t *testing.T) { wallet := newWallet(t, vm, walletConfig{}) - nodeID := ids.GenerateTestNodeID() + nodeID := ids.GenerateTestShortNodeID() startTime := genesistest.DefaultValidatorStartTime.Add(-txexecutor.SyncBound).Add(-1 * time.Second) endTime := startTime.Add(defaultMinStakingDuration) @@ -413,7 +413,7 @@ func TestAddValidatorReject(t *testing.T) { var ( startTime = vm.clock.Time().Add(txexecutor.SyncBound).Add(1 * time.Second) endTime = startTime.Add(defaultMinStakingDuration) - nodeID = ids.GenerateTestNodeID() + nodeID = ids.GenerateTestShortNodeID() rewardAddress = ids.GenerateTestShortID() ) @@ -447,7 +447,7 @@ func TestAddValidatorReject(t *testing.T) { _, _, err = vm.state.GetTx(tx.ID()) require.ErrorIs(err, database.ErrNotFound) - _, err = vm.state.GetPendingValidator(constants.PrimaryNetworkID, nodeID) + _, err = vm.state.GetPendingValidator(constants.PrimaryNetworkID, nodeID.NodeID()) require.ErrorIs(err, database.ErrNotFound) } @@ -478,7 +478,7 @@ func TestAddValidatorInvalidNotReissued(t *testing.T) { tx, err := wallet.IssueAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: repeatNodeID.NodeID(), + NodeID: repeatNodeID, Start: uint64(startTime.Unix()), End: uint64(endTime.Unix()), Wght: vm.MinValidatorStake, @@ -524,7 +524,7 @@ func TestAddSubnetValidatorAccept(t *testing.T) { tx, err := wallet.IssueAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: shortNodeID.NodeID(), + NodeID: shortNodeID, Start: uint64(startTime.Unix()), End: uint64(endTime.Unix()), Wght: genesistest.DefaultValidatorWeight, @@ -573,7 +573,7 @@ func TestAddSubnetValidatorReject(t *testing.T) { tx, err := wallet.IssueAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: shortNodeID.NodeID(), + NodeID: shortNodeID, Start: uint64(startTime.Unix()), End: uint64(endTime.Unix()), Wght: genesistest.DefaultValidatorWeight, @@ -839,7 +839,7 @@ func TestCreateSubnet(t *testing.T) { addValidatorTx, err := wallet.IssueAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: shortNodeID.NodeID(), + NodeID: shortNodeID, Start: uint64(startTime.Unix()), End: uint64(endTime.Unix()), Wght: genesistest.DefaultValidatorWeight, @@ -1897,7 +1897,7 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { wallet := newWallet(t, vm, walletConfig{}) - nodeID := ids.GenerateTestNodeID() + nodeID := ids.GenerateTestShortNodeID() sk, err := bls.NewSecretKey() require.NoError(err) rewardsOwner := &secp256k1fx.OutputOwners{ @@ -1982,7 +1982,7 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { require.NoError(block.Accept(context.Background())) require.NoError(vm.SetPreference(context.Background(), vm.manager.LastAccepted())) - _, err = vm.state.GetPendingValidator(subnetID, nodeID) + _, err = vm.state.GetPendingValidator(subnetID, nodeID.NodeID()) require.ErrorIs(err, database.ErrNotFound) } @@ -2124,7 +2124,7 @@ func TestPruneMempool(t *testing.T) { addValidatorTx, err := wallet.IssueAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: ids.GenerateTestNodeID(), + NodeID: ids.GenerateTestShortNodeID(), Start: uint64(startTime.Unix()), End: uint64(endTime.Unix()), Wght: defaultMinValidatorStake, diff --git a/wallet/chain/p/builder/builder.go b/wallet/chain/p/builder/builder.go index b665617e0e16..bc64f9a4debd 100644 --- a/wallet/chain/p/builder/builder.go +++ b/wallet/chain/p/builder/builder.go @@ -95,7 +95,7 @@ type Builder interface { // NewRemoveSubnetValidatorTx removes [nodeID] from the validator // set [subnetID]. NewRemoveSubnetValidatorTx( - nodeID ids.NodeID, + nodeID ids.ShortNodeID, subnetID ids.ID, options ...common.Option, ) (*txs.RemoveSubnetValidatorTx, error) @@ -468,7 +468,7 @@ func (b *builder) NewAddSubnetValidatorTx( } func (b *builder) NewRemoveSubnetValidatorTx( - nodeID ids.NodeID, + nodeID ids.ShortNodeID, subnetID ids.ID, options ...common.Option, ) (*txs.RemoveSubnetValidatorTx, error) { diff --git a/wallet/chain/p/builder/builder_with_options.go b/wallet/chain/p/builder/builder_with_options.go index d831e0c76daa..05d400373ed0 100644 --- a/wallet/chain/p/builder/builder_with_options.go +++ b/wallet/chain/p/builder/builder_with_options.go @@ -92,7 +92,7 @@ func (b *builderWithOptions) NewAddSubnetValidatorTx( } func (b *builderWithOptions) NewRemoveSubnetValidatorTx( - nodeID ids.NodeID, + nodeID ids.ShortNodeID, subnetID ids.ID, options ...common.Option, ) (*txs.RemoveSubnetValidatorTx, error) { diff --git a/wallet/chain/p/builder_test.go b/wallet/chain/p/builder_test.go index e2a970b909cc..3c9a7ba0a2ec 100644 --- a/wallet/chain/p/builder_test.go +++ b/wallet/chain/p/builder_test.go @@ -34,7 +34,7 @@ import ( var ( subnetID = ids.GenerateTestID() - nodeID = ids.GenerateTestNodeID() + nodeID = ids.GenerateTestShortNodeID() testKeys = secp256k1.TestKeys() subnetAuthKey = testKeys[0] diff --git a/wallet/chain/p/wallet/wallet.go b/wallet/chain/p/wallet/wallet.go index d7414f1b3e28..45affd2fd53a 100644 --- a/wallet/chain/p/wallet/wallet.go +++ b/wallet/chain/p/wallet/wallet.go @@ -77,7 +77,7 @@ type Wallet interface { // // - [nodeID] is the validator being removed from [subnetID]. IssueRemoveSubnetValidatorTx( - nodeID ids.NodeID, + nodeID ids.ShortNodeID, subnetID ids.ID, options ...common.Option, ) (*txs.Tx, error) @@ -314,7 +314,7 @@ func (w *wallet) IssueAddSubnetValidatorTx( } func (w *wallet) IssueRemoveSubnetValidatorTx( - nodeID ids.NodeID, + nodeID ids.ShortNodeID, subnetID ids.ID, options ...common.Option, ) (*txs.Tx, error) { diff --git a/wallet/chain/p/wallet/with_options.go b/wallet/chain/p/wallet/with_options.go index 64b22050a953..8eadfe319118 100644 --- a/wallet/chain/p/wallet/with_options.go +++ b/wallet/chain/p/wallet/with_options.go @@ -80,7 +80,7 @@ func (w *withOptions) IssueAddSubnetValidatorTx( } func (w *withOptions) IssueRemoveSubnetValidatorTx( - nodeID ids.NodeID, + nodeID ids.ShortNodeID, subnetID ids.ID, options ...common.Option, ) (*txs.Tx, error) { diff --git a/wallet/subnet/primary/example_test.go b/wallet/subnet/primary/example_test.go index bfb1505438cf..6c2390e00be4 100644 --- a/wallet/subnet/primary/example_test.go +++ b/wallet/subnet/primary/example_test.go @@ -146,7 +146,7 @@ func ExampleWallet() { addSubnetValidatorTx, err := pWallet.IssueAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: genesis.LocalConfig.InitialStakers[0].NodeID.NodeID(), + NodeID: genesis.LocalConfig.InitialStakers[0].NodeID, Start: uint64(startTime.Unix()), End: uint64(startTime.Add(5 * time.Second).Unix()), Wght: 25 * units.MegaAvax, @@ -170,7 +170,7 @@ func ExampleWallet() { addSubnetDelegatorTx, err := pWallet.IssueAddPermissionlessDelegatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: genesis.LocalConfig.InitialStakers[0].NodeID.NodeID(), + NodeID: genesis.LocalConfig.InitialStakers[0].NodeID, Start: uint64(startTime.Unix()), End: uint64(startTime.Add(5 * time.Second).Unix()), Wght: 25 * units.MegaAvax, diff --git a/wallet/subnet/primary/examples/add-permissioned-subnet-validator/main.go b/wallet/subnet/primary/examples/add-permissioned-subnet-validator/main.go index 055abdf21221..5bd3347392af 100644 --- a/wallet/subnet/primary/examples/add-permissioned-subnet-validator/main.go +++ b/wallet/subnet/primary/examples/add-permissioned-subnet-validator/main.go @@ -59,9 +59,13 @@ func main() { pWallet := wallet.P() addValidatorStartTime := time.Now() + shortNodeID, err := ids.ShortNodeIDFromNodeID(nodeID) + if err != nil { + log.Fatalf("failed turning NodeID %s into shortNodeID: %s\n", nodeID, err) + } addValidatorTx, err := pWallet.IssueAddSubnetValidatorTx(&txs.SubnetValidator{ Validator: txs.Validator{ - NodeID: nodeID, + NodeID: shortNodeID, Start: uint64(startTime.Unix()), End: uint64(startTime.Add(duration).Unix()), Wght: weight, diff --git a/wallet/subnet/primary/examples/add-primary-validator/main.go b/wallet/subnet/primary/examples/add-primary-validator/main.go index 7c2b6c055855..446c056c5562 100644 --- a/wallet/subnet/primary/examples/add-primary-validator/main.go +++ b/wallet/subnet/primary/examples/add-primary-validator/main.go @@ -59,9 +59,13 @@ func main() { avaxAssetID := pContext.AVAXAssetID addValidatorStartTime := time.Now() + shortNodeID, err := ids.ShortNodeIDFromNodeID(nodeID) + if err != nil { + log.Fatalf("failed turning NodeID %s into shortNodeID: %s\n", nodeID, err) + } addValidatorTx, err := pWallet.IssueAddPermissionlessValidatorTx( &txs.SubnetValidator{Validator: txs.Validator{ - NodeID: nodeID, + NodeID: shortNodeID, Start: uint64(startTime.Unix()), End: uint64(startTime.Add(duration).Unix()), Wght: weight, diff --git a/wallet/subnet/primary/examples/remove-subnet-validator/main.go b/wallet/subnet/primary/examples/remove-subnet-validator/main.go index 2916d63bb3cb..154a18f3ff68 100644 --- a/wallet/subnet/primary/examples/remove-subnet-validator/main.go +++ b/wallet/subnet/primary/examples/remove-subnet-validator/main.go @@ -26,7 +26,7 @@ func main() { log.Fatalf("failed to parse subnet ID: %s\n", err) } - nodeID, err := ids.NodeIDFromString(nodeIDStr) + nodeID, err := ids.ShortNodeIDFromString(nodeIDStr) if err != nil { log.Fatalf("failed to parse node ID: %s\n", err) } From 68845b47e33802892aeeed706d1a74256b7c4f12 Mon Sep 17 00:00:00 2001 From: tsachiherman <24438559+tsachiherman@users.noreply.github.com> Date: Tue, 27 Aug 2024 16:23:51 -0400 Subject: [PATCH 12/17] rollback appsender_server changes. --- ids/node_id.go | 5 +++++ snow/engine/common/appsender/appsender_server.go | 16 ++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/ids/node_id.go b/ids/node_id.go index 9cccc9cebf13..f27382273e48 100644 --- a/ids/node_id.go +++ b/ids/node_id.go @@ -31,3 +31,8 @@ func NodeIDFromString(nodeIDStr string) (NodeID, error) { } return NodeID{ShortNodeID: ShortNodeID(asShort)}, nil } + +func ToNodeID(bytes []byte) (NodeID, error) { + nodeID, err := ToShortID(bytes) + return NodeID{ShortNodeID: ShortNodeID(nodeID)}, err +} diff --git a/snow/engine/common/appsender/appsender_server.go b/snow/engine/common/appsender/appsender_server.go index aec3f2d6d878..73092d3e0860 100644 --- a/snow/engine/common/appsender/appsender_server.go +++ b/snow/engine/common/appsender/appsender_server.go @@ -30,43 +30,43 @@ func NewServer(appSender common.AppSender) *Server { func (s *Server) SendAppRequest(ctx context.Context, req *appsenderpb.SendAppRequestMsg) (*emptypb.Empty, error) { nodeIDs := set.NewSet[ids.NodeID](len(req.NodeIds)) for _, nodeIDBytes := range req.NodeIds { - shortNodeID, err := ids.ToShortNodeID(nodeIDBytes) + nodeID, err := ids.ToNodeID(nodeIDBytes) if err != nil { return nil, err } - nodeIDs.Add(shortNodeID.NodeID()) + nodeIDs.Add(nodeID) } err := s.appSender.SendAppRequest(ctx, nodeIDs, req.RequestId, req.Request) return &emptypb.Empty{}, err } func (s *Server) SendAppResponse(ctx context.Context, req *appsenderpb.SendAppResponseMsg) (*emptypb.Empty, error) { - shortNodeID, err := ids.ToShortNodeID(req.NodeId) + nodeID, err := ids.ToNodeID(req.NodeId) if err != nil { return nil, err } - err = s.appSender.SendAppResponse(ctx, shortNodeID.NodeID(), req.RequestId, req.Response) + err = s.appSender.SendAppResponse(ctx, nodeID, req.RequestId, req.Response) return &emptypb.Empty{}, err } func (s *Server) SendAppError(ctx context.Context, req *appsenderpb.SendAppErrorMsg) (*emptypb.Empty, error) { - shortNodeID, err := ids.ToShortNodeID(req.NodeId) + nodeID, err := ids.ToNodeID(req.NodeId) if err != nil { return nil, err } - err = s.appSender.SendAppError(ctx, shortNodeID.NodeID(), req.RequestId, req.ErrorCode, req.ErrorMessage) + err = s.appSender.SendAppError(ctx, nodeID, req.RequestId, req.ErrorCode, req.ErrorMessage) return &emptypb.Empty{}, err } func (s *Server) SendAppGossip(ctx context.Context, req *appsenderpb.SendAppGossipMsg) (*emptypb.Empty, error) { nodeIDs := set.NewSet[ids.NodeID](len(req.NodeIds)) for _, nodeIDBytes := range req.NodeIds { - shortNodeID, err := ids.ToShortNodeID(nodeIDBytes) + nodeID, err := ids.ToNodeID(nodeIDBytes) if err != nil { return nil, err } - nodeIDs.Add(shortNodeID.NodeID()) + nodeIDs.Add(nodeID) } err := s.appSender.SendAppGossip( ctx, From 111c0fe33112a746c575b87dea47b388a1e4da4e Mon Sep 17 00:00:00 2001 From: tsachiherman <24438559+tsachiherman@users.noreply.github.com> Date: Tue, 27 Aug 2024 16:36:28 -0400 Subject: [PATCH 13/17] fix unit test --- vms/platformvm/block/executor/block_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/vms/platformvm/block/executor/block_test.go b/vms/platformvm/block/executor/block_test.go index bc4d0dbde402..7fdf4c5eb9bd 100644 --- a/vms/platformvm/block/executor/block_test.go +++ b/vms/platformvm/block/executor/block_test.go @@ -229,7 +229,7 @@ func TestBlockOptions(t *testing.T) { state := state.NewMockState(ctrl) state.EXPECT().GetTx(stakerTxID).Return(stakerTx, status.Committed, nil) - state.EXPECT().GetCurrentValidator(constants.PrimaryNetworkID, nodeID).Return(nil, database.ErrNotFound) + state.EXPECT().GetCurrentValidator(constants.PrimaryNetworkID, nodeID.NodeID()).Return(nil, database.ErrNotFound) uptimes := uptimemock.NewCalculator(ctrl) @@ -284,10 +284,10 @@ func TestBlockOptions(t *testing.T) { state := state.NewMockState(ctrl) state.EXPECT().GetTx(stakerTxID).Return(stakerTx, status.Committed, nil) - state.EXPECT().GetCurrentValidator(constants.PrimaryNetworkID, nodeID).Return(staker, nil) + state.EXPECT().GetCurrentValidator(constants.PrimaryNetworkID, nodeID.NodeID()).Return(staker, nil) uptimes := uptimemock.NewCalculator(ctrl) - uptimes.EXPECT().CalculateUptimePercentFrom(nodeID, constants.PrimaryNetworkID, primaryNetworkValidatorStartTime).Return(0.0, database.ErrNotFound) + uptimes.EXPECT().CalculateUptimePercentFrom(nodeID.NodeID(), constants.PrimaryNetworkID, primaryNetworkValidatorStartTime).Return(0.0, database.ErrNotFound) manager := &manager{ backend: &backend{ @@ -340,7 +340,7 @@ func TestBlockOptions(t *testing.T) { state := state.NewMockState(ctrl) state.EXPECT().GetTx(stakerTxID).Return(stakerTx, status.Committed, nil) - state.EXPECT().GetCurrentValidator(constants.PrimaryNetworkID, nodeID).Return(staker, nil) + state.EXPECT().GetCurrentValidator(constants.PrimaryNetworkID, nodeID.NodeID()).Return(staker, nil) state.EXPECT().GetSubnetTransformation(subnetID).Return(nil, database.ErrNotFound) uptimes := uptimemock.NewCalculator(ctrl) @@ -401,11 +401,11 @@ func TestBlockOptions(t *testing.T) { state := state.NewMockState(ctrl) state.EXPECT().GetTx(stakerTxID).Return(stakerTx, status.Committed, nil) - state.EXPECT().GetCurrentValidator(constants.PrimaryNetworkID, nodeID).Return(staker, nil) + state.EXPECT().GetCurrentValidator(constants.PrimaryNetworkID, nodeID.NodeID()).Return(staker, nil) state.EXPECT().GetSubnetTransformation(subnetID).Return(transformSubnetTx, nil) uptimes := uptimemock.NewCalculator(ctrl) - uptimes.EXPECT().CalculateUptimePercentFrom(nodeID, constants.PrimaryNetworkID, primaryNetworkValidatorStartTime).Return(.5, nil) + uptimes.EXPECT().CalculateUptimePercentFrom(nodeID.NodeID(), constants.PrimaryNetworkID, primaryNetworkValidatorStartTime).Return(.5, nil) manager := &manager{ backend: &backend{ @@ -463,11 +463,11 @@ func TestBlockOptions(t *testing.T) { state := state.NewMockState(ctrl) state.EXPECT().GetTx(stakerTxID).Return(stakerTx, status.Committed, nil) - state.EXPECT().GetCurrentValidator(constants.PrimaryNetworkID, nodeID).Return(staker, nil) + state.EXPECT().GetCurrentValidator(constants.PrimaryNetworkID, nodeID.NodeID()).Return(staker, nil) state.EXPECT().GetSubnetTransformation(subnetID).Return(transformSubnetTx, nil) uptimes := uptimemock.NewCalculator(ctrl) - uptimes.EXPECT().CalculateUptimePercentFrom(nodeID, constants.PrimaryNetworkID, primaryNetworkValidatorStartTime).Return(.5, nil) + uptimes.EXPECT().CalculateUptimePercentFrom(nodeID.NodeID(), constants.PrimaryNetworkID, primaryNetworkValidatorStartTime).Return(.5, nil) manager := &manager{ backend: &backend{ From 09349760d693d0dd16ff3184196d88666b51e9c2 Mon Sep 17 00:00:00 2001 From: tsachiherman <24438559+tsachiherman@users.noreply.github.com> Date: Wed, 28 Aug 2024 09:59:03 -0400 Subject: [PATCH 14/17] fix unit tests --- .../txs/executor/standard_tx_executor_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index 05759547b2cb..a62286f1f5b6 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -1737,7 +1737,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { // Set dependency expectations. env.state.EXPECT().GetTimestamp().Return(env.latestForkTime).AnyTimes() - env.state.EXPECT().GetCurrentValidator(env.unsignedTx.Subnet, env.unsignedTx.NodeID).Return(env.staker, nil).Times(1) + env.state.EXPECT().GetCurrentValidator(env.unsignedTx.Subnet, env.unsignedTx.NodeID.NodeID()).Return(env.staker, nil).Times(1) subnetOwner := fxmock.NewOwner(ctrl) env.state.EXPECT().GetSubnetOwner(env.unsignedTx.Subnet).Return(subnetOwner, nil).Times(1) env.fx.EXPECT().VerifyPermission(env.unsignedTx, env.unsignedTx.SubnetAuth, env.tx.Creds[len(env.tx.Creds)-1], subnetOwner).Return(nil).Times(1) @@ -1805,8 +1805,8 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { env := newValidRemoveSubnetValidatorTxVerifyEnv(t, ctrl) env.state = state.NewMockDiff(ctrl) env.state.EXPECT().GetTimestamp().Return(env.latestForkTime).AnyTimes() - env.state.EXPECT().GetCurrentValidator(env.unsignedTx.Subnet, env.unsignedTx.NodeID).Return(nil, database.ErrNotFound) - env.state.EXPECT().GetPendingValidator(env.unsignedTx.Subnet, env.unsignedTx.NodeID).Return(nil, database.ErrNotFound) + env.state.EXPECT().GetCurrentValidator(env.unsignedTx.Subnet, env.unsignedTx.NodeID.NodeID()).Return(nil, database.ErrNotFound) + env.state.EXPECT().GetPendingValidator(env.unsignedTx.Subnet, env.unsignedTx.NodeID.NodeID()).Return(nil, database.ErrNotFound) cfg := &config.Config{ UpgradeConfig: upgradetest.GetConfigWithUpgradeTime(upgradetest.Durango, env.latestForkTime), @@ -1839,7 +1839,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { // Set dependency expectations. env.state.EXPECT().GetTimestamp().Return(env.latestForkTime).AnyTimes() - env.state.EXPECT().GetCurrentValidator(env.unsignedTx.Subnet, env.unsignedTx.NodeID).Return(&staker, nil).Times(1) + env.state.EXPECT().GetCurrentValidator(env.unsignedTx.Subnet, env.unsignedTx.NodeID.NodeID()).Return(&staker, nil).Times(1) cfg := &config.Config{ UpgradeConfig: upgradetest.GetConfigWithUpgradeTime(upgradetest.Durango, env.latestForkTime), @@ -1870,7 +1870,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { env.tx.Creds = nil env.state = state.NewMockDiff(ctrl) env.state.EXPECT().GetTimestamp().Return(env.latestForkTime).AnyTimes() - env.state.EXPECT().GetCurrentValidator(env.unsignedTx.Subnet, env.unsignedTx.NodeID).Return(env.staker, nil) + env.state.EXPECT().GetCurrentValidator(env.unsignedTx.Subnet, env.unsignedTx.NodeID.NodeID()).Return(env.staker, nil) cfg := &config.Config{ UpgradeConfig: upgradetest.GetConfigWithUpgradeTime(upgradetest.Durango, env.latestForkTime), @@ -1899,7 +1899,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { env := newValidRemoveSubnetValidatorTxVerifyEnv(t, ctrl) env.state = state.NewMockDiff(ctrl) env.state.EXPECT().GetTimestamp().Return(env.latestForkTime).AnyTimes() - env.state.EXPECT().GetCurrentValidator(env.unsignedTx.Subnet, env.unsignedTx.NodeID).Return(env.staker, nil) + env.state.EXPECT().GetCurrentValidator(env.unsignedTx.Subnet, env.unsignedTx.NodeID.NodeID()).Return(env.staker, nil) env.state.EXPECT().GetSubnetOwner(env.unsignedTx.Subnet).Return(nil, database.ErrNotFound) cfg := &config.Config{ @@ -1929,7 +1929,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { env := newValidRemoveSubnetValidatorTxVerifyEnv(t, ctrl) env.state = state.NewMockDiff(ctrl) env.state.EXPECT().GetTimestamp().Return(env.latestForkTime).AnyTimes() - env.state.EXPECT().GetCurrentValidator(env.unsignedTx.Subnet, env.unsignedTx.NodeID).Return(env.staker, nil) + env.state.EXPECT().GetCurrentValidator(env.unsignedTx.Subnet, env.unsignedTx.NodeID.NodeID()).Return(env.staker, nil) subnetOwner := fxmock.NewOwner(ctrl) env.state.EXPECT().GetSubnetOwner(env.unsignedTx.Subnet).Return(subnetOwner, nil) env.fx.EXPECT().VerifyPermission(gomock.Any(), env.unsignedTx.SubnetAuth, env.tx.Creds[len(env.tx.Creds)-1], subnetOwner).Return(errTest) @@ -1961,7 +1961,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { env := newValidRemoveSubnetValidatorTxVerifyEnv(t, ctrl) env.state = state.NewMockDiff(ctrl) env.state.EXPECT().GetTimestamp().Return(env.latestForkTime).AnyTimes() - env.state.EXPECT().GetCurrentValidator(env.unsignedTx.Subnet, env.unsignedTx.NodeID).Return(env.staker, nil) + env.state.EXPECT().GetCurrentValidator(env.unsignedTx.Subnet, env.unsignedTx.NodeID.NodeID()).Return(env.staker, nil) subnetOwner := fxmock.NewOwner(ctrl) env.state.EXPECT().GetSubnetOwner(env.unsignedTx.Subnet).Return(subnetOwner, nil) env.fx.EXPECT().VerifyPermission(gomock.Any(), env.unsignedTx.SubnetAuth, env.tx.Creds[len(env.tx.Creds)-1], subnetOwner).Return(nil) From 181b8c624bce70c37509b9de2b440faffd48477e Mon Sep 17 00:00:00 2001 From: tsachiherman <24438559+tsachiherman@users.noreply.github.com> Date: Tue, 3 Sep 2024 11:33:03 -0400 Subject: [PATCH 15/17] update per CR --- ids/node_id.go | 18 +++++++++++- .../state/disk_staker_diff_iterator.go | 26 ++++++++++------- vms/rpcchainvm/vm_server.go | 28 +++++++++---------- 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/ids/node_id.go b/ids/node_id.go index f27382273e48..0454d682b7f6 100644 --- a/ids/node_id.go +++ b/ids/node_id.go @@ -3,16 +3,23 @@ package ids -import "github.com/ava-labs/avalanchego/utils" +import ( + "errors" + + "github.com/ava-labs/avalanchego/utils" +) const ( NodeIDPrefix = "NodeID-" + NodeIDLen = ShortIDLen // this would eventually be updated to 32 byte length. ) var ( EmptyNodeID = NodeID{} _ utils.Sortable[NodeID] = NodeID{} + + errWrongNodeIDLength = errors.New("wrong NodeID length") ) type NodeID struct { @@ -36,3 +43,12 @@ func ToNodeID(bytes []byte) (NodeID, error) { nodeID, err := ToShortID(bytes) return NodeID{ShortNodeID: ShortNodeID(nodeID)}, err } + +func ParseNodeID(bytes []byte) (NodeID, error) { + if len(bytes) == ShortIDLen { + var node NodeID + copy(node.ShortNodeID[:], bytes[:]) + return node, nil + } + return NodeID{}, errWrongNodeIDLength +} diff --git a/vms/platformvm/state/disk_staker_diff_iterator.go b/vms/platformvm/state/disk_staker_diff_iterator.go index f114a28d8ac0..439fa3480d76 100644 --- a/vms/platformvm/state/disk_staker_diff_iterator.go +++ b/vms/platformvm/state/disk_staker_diff_iterator.go @@ -14,8 +14,8 @@ import ( const ( // startDiffKey = [subnetID] + [inverseHeight] startDiffKeyLength = ids.IDLen + database.Uint64Size - // diffKey = [subnetID] + [inverseHeight] + [nodeID] - diffKeyLength = startDiffKeyLength + ids.ShortNodeIDLen + // diffKey = [subnetID] + [inverseHeight] + [shortNodeID]/[NodeID] + minDiffKeyLength = startDiffKeyLength + ids.ShortNodeIDLen // diffKeyNodeIDOffset = [subnetIDLen] + [inverseHeightLen] diffKeyNodeIDOffset = ids.IDLen + database.Uint64Size @@ -24,7 +24,7 @@ const ( ) var ( - errUnexpectedDiffKeyLength = fmt.Errorf("expected diff key length %d", diffKeyLength) + errUnexpectedDiffKeyLength = fmt.Errorf("expected min diff key length of %d", minDiffKeyLength) errUnexpectedWeightValueLength = fmt.Errorf("expected weight value length %d", weightValueLength) ) @@ -40,25 +40,31 @@ func marshalStartDiffKey(subnetID ids.ID, height uint64) []byte { } func marshalDiffKey(subnetID ids.ID, height uint64, nodeID ids.NodeID) []byte { - key := make([]byte, diffKeyLength) + nodeIDBytes := nodeID.Bytes() + keyLength := startDiffKeyLength + len(nodeIDBytes) + key := make([]byte, keyLength) copy(key, subnetID[:]) packIterableHeight(key[ids.IDLen:], height) - copy(key[diffKeyNodeIDOffset:], nodeID.Bytes()) + copy(key[diffKeyNodeIDOffset:], nodeIDBytes) return key } func unmarshalDiffKey(key []byte) (ids.ID, uint64, ids.NodeID, error) { - if len(key) != diffKeyLength { + if len(key) < minDiffKeyLength { return ids.Empty, 0, ids.EmptyNodeID, errUnexpectedDiffKeyLength } var ( - subnetID ids.ID - shortNodeID ids.ShortNodeID + subnetID ids.ID + nodeID ids.NodeID + err error ) + nodeID, err = ids.ParseNodeID(key[diffKeyNodeIDOffset:]) + if err != nil { + return ids.Empty, 0, ids.EmptyNodeID, errUnexpectedDiffKeyLength + } copy(subnetID[:], key) height := unpackIterableHeight(key[ids.IDLen:]) - copy(shortNodeID[:], key[diffKeyNodeIDOffset:]) - return subnetID, height, shortNodeID.NodeID(), nil + return subnetID, height, nodeID, err } func marshalWeightDiff(diff *ValidatorWeightDiff) []byte { diff --git a/vms/rpcchainvm/vm_server.go b/vms/rpcchainvm/vm_server.go index 8905974c1603..a5a9266a2434 100644 --- a/vms/rpcchainvm/vm_server.go +++ b/vms/rpcchainvm/vm_server.go @@ -106,7 +106,7 @@ func (vm *VMServer) Initialize(ctx context.Context, req *vmpb.InitializeRequest) if err != nil { return nil, err } - shortNodeID, err := ids.ToShortNodeID(req.NodeId) + nodeID, err := ids.ToNodeID(req.NodeId) if err != nil { return nil, err } @@ -241,7 +241,7 @@ func (vm *VMServer) Initialize(ctx context.Context, req *vmpb.InitializeRequest) NetworkID: req.NetworkId, SubnetID: subnetID, ChainID: chainID, - NodeID: shortNodeID.NodeID(), + NodeID: nodeID, PublicKey: publicKey, NetworkUpgrades: networkUpgrades, @@ -364,7 +364,7 @@ func (vm *VMServer) CreateHandlers(ctx context.Context, _ *emptypb.Empty) (*vmpb } func (vm *VMServer) Connected(ctx context.Context, req *vmpb.ConnectedRequest) (*emptypb.Empty, error) { - shortNodeID, err := ids.ToShortNodeID(req.NodeId) + nodeID, err := ids.ToNodeID(req.NodeId) if err != nil { return nil, err } @@ -375,15 +375,15 @@ func (vm *VMServer) Connected(ctx context.Context, req *vmpb.ConnectedRequest) ( Minor: int(req.Minor), Patch: int(req.Patch), } - return &emptypb.Empty{}, vm.vm.Connected(ctx, shortNodeID.NodeID(), peerVersion) + return &emptypb.Empty{}, vm.vm.Connected(ctx, nodeID, peerVersion) } func (vm *VMServer) Disconnected(ctx context.Context, req *vmpb.DisconnectedRequest) (*emptypb.Empty, error) { - shortNodeID, err := ids.ToShortNodeID(req.NodeId) + nodeID, err := ids.ToNodeID(req.NodeId) if err != nil { return nil, err } - return &emptypb.Empty{}, vm.vm.Disconnected(ctx, shortNodeID.NodeID()) + return &emptypb.Empty{}, vm.vm.Disconnected(ctx, nodeID) } // If the underlying VM doesn't actually implement this method, its [BuildBlock] @@ -519,7 +519,7 @@ func (vm *VMServer) Version(ctx context.Context, _ *emptypb.Empty) (*vmpb.Versio } func (vm *VMServer) AppRequest(ctx context.Context, req *vmpb.AppRequestMsg) (*emptypb.Empty, error) { - shortNodeID, err := ids.ToShortNodeID(req.NodeId) + nodeID, err := ids.ToNodeID(req.NodeId) if err != nil { return nil, err } @@ -527,11 +527,11 @@ func (vm *VMServer) AppRequest(ctx context.Context, req *vmpb.AppRequestMsg) (*e if err != nil { return nil, err } - return &emptypb.Empty{}, vm.vm.AppRequest(ctx, shortNodeID.NodeID(), req.RequestId, deadline, req.Request) + return &emptypb.Empty{}, vm.vm.AppRequest(ctx, nodeID, req.RequestId, deadline, req.Request) } func (vm *VMServer) AppRequestFailed(ctx context.Context, req *vmpb.AppRequestFailedMsg) (*emptypb.Empty, error) { - shortNodeID, err := ids.ToShortNodeID(req.NodeId) + nodeID, err := ids.ToNodeID(req.NodeId) if err != nil { return nil, err } @@ -540,23 +540,23 @@ func (vm *VMServer) AppRequestFailed(ctx context.Context, req *vmpb.AppRequestFa Code: req.ErrorCode, Message: req.ErrorMessage, } - return &emptypb.Empty{}, vm.vm.AppRequestFailed(ctx, shortNodeID.NodeID(), req.RequestId, appErr) + return &emptypb.Empty{}, vm.vm.AppRequestFailed(ctx, nodeID, req.RequestId, appErr) } func (vm *VMServer) AppResponse(ctx context.Context, req *vmpb.AppResponseMsg) (*emptypb.Empty, error) { - shortNodeID, err := ids.ToShortNodeID(req.NodeId) + nodeID, err := ids.ToNodeID(req.NodeId) if err != nil { return nil, err } - return &emptypb.Empty{}, vm.vm.AppResponse(ctx, shortNodeID.NodeID(), req.RequestId, req.Response) + return &emptypb.Empty{}, vm.vm.AppResponse(ctx, nodeID, req.RequestId, req.Response) } func (vm *VMServer) AppGossip(ctx context.Context, req *vmpb.AppGossipMsg) (*emptypb.Empty, error) { - shortNodeID, err := ids.ToShortNodeID(req.NodeId) + nodeID, err := ids.ToNodeID(req.NodeId) if err != nil { return nil, err } - return &emptypb.Empty{}, vm.vm.AppGossip(ctx, shortNodeID.NodeID(), req.Msg) + return &emptypb.Empty{}, vm.vm.AppGossip(ctx, nodeID, req.Msg) } func (vm *VMServer) Gather(context.Context, *emptypb.Empty) (*vmpb.GatherResponse, error) { From ae9598ac5eaca9e0f216059891c04dce443079b5 Mon Sep 17 00:00:00 2001 From: tsachiherman <24438559+tsachiherman@users.noreply.github.com> Date: Tue, 3 Sep 2024 11:46:50 -0400 Subject: [PATCH 16/17] fix linter --- ids/node_id.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ids/node_id.go b/ids/node_id.go index 0454d682b7f6..55144479ea6b 100644 --- a/ids/node_id.go +++ b/ids/node_id.go @@ -47,7 +47,7 @@ func ToNodeID(bytes []byte) (NodeID, error) { func ParseNodeID(bytes []byte) (NodeID, error) { if len(bytes) == ShortIDLen { var node NodeID - copy(node.ShortNodeID[:], bytes[:]) + copy(node.ShortNodeID[:], bytes) return node, nil } return NodeID{}, errWrongNodeIDLength From 0af70b1fef3e491a28273e02d5e86b26cbd91cbd Mon Sep 17 00:00:00 2001 From: tsachiherman <24438559+tsachiherman@users.noreply.github.com> Date: Tue, 3 Sep 2024 16:46:54 -0400 Subject: [PATCH 17/17] fix merge with master --- vms/platformvm/vm_regression_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index a9ff520f8159..4fab420146a9 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -1403,7 +1403,7 @@ func TestAddValidatorDuringRemoval(t *testing.T) { require.NoError(buildAndAcceptStandardBlock(vm)) // Verify that the validator was added - _, err = vm.state.GetCurrentValidator(subnetID, nodeID) + _, err = vm.state.GetCurrentValidator(subnetID, nodeID.NodeID()) require.NoError(err) secondEndTime := firstEndTime.Add(duration) @@ -1427,7 +1427,7 @@ func TestAddValidatorDuringRemoval(t *testing.T) { require.NoError(buildAndAcceptStandardBlock(vm)) // Verify that the validator does not exist - _, err = vm.state.GetCurrentValidator(subnetID, nodeID) + _, err = vm.state.GetCurrentValidator(subnetID, nodeID.NodeID()) require.ErrorIs(err, database.ErrNotFound) // Verify that the invalid transaction was not executed