Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ids.Empty instead of ids.ID{} #3166

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chains/test_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (testManager) StartChainCreator(ChainParameters) error {
}

func (testManager) SubnetID(ids.ID) (ids.ID, error) {
return ids.ID{}, nil
return ids.Empty, nil
}

func (testManager) IsBootstrapped(ids.ID) bool {
Expand Down
2 changes: 1 addition & 1 deletion database/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func PutID(db KeyValueWriter, key []byte, val ids.ID) error {
func GetID(db KeyValueReader, key []byte) (ids.ID, error) {
b, err := db.Get(key)
if err != nil {
return ids.ID{}, err
return ids.Empty, err
}
return ids.ToID(b)
}
Expand Down
32 changes: 16 additions & 16 deletions genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func validateConfig(networkID uint32, config *Config, stakingCfg *StakingConfig)
func FromFile(networkID uint32, filepath string, stakingCfg *StakingConfig) ([]byte, ids.ID, error) {
switch networkID {
case constants.MainnetID, constants.TestnetID, constants.LocalID:
return nil, ids.ID{}, fmt.Errorf(
return nil, ids.Empty, fmt.Errorf(
"%w: %s",
errOverridesStandardNetworkConfig,
constants.NetworkName(networkID),
Expand All @@ -212,11 +212,11 @@ func FromFile(networkID uint32, filepath string, stakingCfg *StakingConfig) ([]b

config, err := GetConfigFile(filepath)
if err != nil {
return nil, ids.ID{}, fmt.Errorf("unable to load provided genesis config at %s: %w", filepath, err)
return nil, ids.Empty, fmt.Errorf("unable to load provided genesis config at %s: %w", filepath, err)
}

if err := validateConfig(networkID, config, stakingCfg); err != nil {
return nil, ids.ID{}, fmt.Errorf("genesis config validation failed: %w", err)
return nil, ids.Empty, fmt.Errorf("genesis config validation failed: %w", err)
}

return FromConfig(config)
Expand Down Expand Up @@ -245,7 +245,7 @@ func FromFile(networkID uint32, filepath string, stakingCfg *StakingConfig) ([]b
func FromFlag(networkID uint32, genesisContent string, stakingCfg *StakingConfig) ([]byte, ids.ID, error) {
switch networkID {
case constants.MainnetID, constants.TestnetID, constants.LocalID:
return nil, ids.ID{}, fmt.Errorf(
return nil, ids.Empty, fmt.Errorf(
"%w: %s",
errOverridesStandardNetworkConfig,
constants.NetworkName(networkID),
Expand All @@ -254,11 +254,11 @@ func FromFlag(networkID uint32, genesisContent string, stakingCfg *StakingConfig

customConfig, err := GetConfigContent(genesisContent)
if err != nil {
return nil, ids.ID{}, fmt.Errorf("unable to load genesis content from flag: %w", err)
return nil, ids.Empty, fmt.Errorf("unable to load genesis content from flag: %w", err)
}

if err := validateConfig(networkID, customConfig, stakingCfg); err != nil {
return nil, ids.ID{}, fmt.Errorf("genesis config validation failed: %w", err)
return nil, ids.Empty, fmt.Errorf("genesis config validation failed: %w", err)
}

return FromConfig(customConfig)
Expand Down Expand Up @@ -298,7 +298,7 @@ func FromConfig(config *Config) ([]byte, ids.ID, error) {
for _, allocation := range xAllocations {
addr, err := address.FormatBech32(hrp, allocation.AVAXAddr.Bytes())
if err != nil {
return nil, ids.ID{}, err
return nil, ids.Empty, err
}

avax.InitialState["fixedCap"] = append(avax.InitialState["fixedCap"], avm.Holder{
Expand All @@ -323,22 +323,22 @@ func FromConfig(config *Config) ([]byte, ids.ID, error) {
avmSS := avm.CreateStaticService()
err := avmSS.BuildGenesis(nil, &avmArgs, &avmReply)
if err != nil {
return nil, ids.ID{}, err
return nil, ids.Empty, err
}

bytes, err := formatting.Decode(defaultEncoding, avmReply.Bytes)
if err != nil {
return nil, ids.ID{}, fmt.Errorf("couldn't parse avm genesis reply: %w", err)
return nil, ids.Empty, fmt.Errorf("couldn't parse avm genesis reply: %w", err)
}
avaxAssetID, err := AVAXAssetID(bytes)
if err != nil {
return nil, ids.ID{}, fmt.Errorf("couldn't generate AVAX asset ID: %w", err)
return nil, ids.Empty, fmt.Errorf("couldn't generate AVAX asset ID: %w", err)
}

genesisTime := time.Unix(int64(config.StartTime), 0)
initialSupply, err := config.InitialSupply()
if err != nil {
return nil, ids.ID{}, fmt.Errorf("couldn't calculate the initial supply: %w", err)
return nil, ids.Empty, fmt.Errorf("couldn't calculate the initial supply: %w", err)
}

initiallyStaked := set.Of(config.InitialStakedFunds...)
Expand All @@ -360,7 +360,7 @@ func FromConfig(config *Config) ([]byte, ids.ID, error) {
}
addr, err := address.FormatBech32(hrp, allocation.AVAXAddr.Bytes())
if err != nil {
return nil, ids.ID{}, err
return nil, ids.Empty, err
}
for _, unlock := range allocation.UnlockSchedule {
if unlock.Amount > 0 {
Expand Down Expand Up @@ -391,14 +391,14 @@ func FromConfig(config *Config) ([]byte, ids.ID, error) {

destAddrStr, err := address.FormatBech32(hrp, staker.RewardAddress.Bytes())
if err != nil {
return nil, ids.ID{}, err
return nil, ids.Empty, err
}

utxos := []api.UTXO(nil)
for _, allocation := range nodeAllocations {
addr, err := address.FormatBech32(hrp, allocation.AVAXAddr.Bytes())
if err != nil {
return nil, ids.ID{}, err
return nil, ids.Empty, err
}
for _, unlock := range allocation.UnlockSchedule {
msgStr, err := formatting.Encode(defaultEncoding, allocation.ETHAddr.Bytes())
Expand Down Expand Up @@ -463,12 +463,12 @@ func FromConfig(config *Config) ([]byte, ids.ID, error) {
platformvmReply := api.BuildGenesisReply{}
platformvmSS := api.StaticService{}
if err := platformvmSS.BuildGenesis(nil, &platformvmArgs, &platformvmReply); err != nil {
return nil, ids.ID{}, fmt.Errorf("problem while building platform chain's genesis state: %w", err)
return nil, ids.Empty, fmt.Errorf("problem while building platform chain's genesis state: %w", err)
}

genesisBytes, err := formatting.Decode(platformvmReply.Encoding, platformvmReply.Bytes)
if err != nil {
return nil, ids.ID{}, fmt.Errorf("problem parsing platformvm genesis bytes: %w", err)
return nil, ids.Empty, fmt.Errorf("problem parsing platformvm genesis bytes: %w", err)
}

return genesisBytes, avaxAssetID, nil
Expand Down
2 changes: 1 addition & 1 deletion ids/galiasreader/alias_reader_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (c *Client) Lookup(alias string) (ids.ID, error) {
Alias: alias,
})
if err != nil {
return ids.ID{}, err
return ids.Empty, err
}
return ids.ToID(resp.Id)
}
Expand Down
4 changes: 2 additions & 2 deletions snow/consensus/snowman/topological.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ func (ts *Topological) vote(ctx context.Context, voteStack []votes) (ids.ID, err
// block.
if parentBlock.sb.Finalized() && ts.lastAcceptedID == vote.parentID {
if err := ts.acceptPreferredChild(ctx, parentBlock); err != nil {
return ids.ID{}, err
return ids.Empty, err
}

// by accepting the child of parentBlock, the last accepted block is
Expand All @@ -522,7 +522,7 @@ func (ts *Topological) vote(ctx context.Context, voteStack []votes) (ids.ID, err
// children will need to have their confidence reset. If there isn't a
// child having RecordPoll called, then the nextID will default to the
// nil ID.
nextID := ids.ID{}
nextID := ids.Empty
if len(voteStack) > 0 {
nextID = voteStack[newStackSize-1].parentID
}
Expand Down
2 changes: 1 addition & 1 deletion snow/engine/avalanche/bootstrap/queue/test_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (j *TestJob) ID() ids.ID {
if j.CantID && j.T != nil {
require.FailNow(j.T, "Unexpectedly called ID")
}
return ids.ID{}
return ids.Empty
}

func (j *TestJob) MissingDependencies(ctx context.Context) (set.Set[ids.ID], error) {
Expand Down
33 changes: 15 additions & 18 deletions snow/engine/avalanche/state/unique_vertex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestUnknownUniqueVertexErrors(t *testing.T) {

uVtx := &uniqueVertex{
serializer: s,
id: ids.ID{},
id: ids.Empty,
}

status := uVtx.Status()
Expand Down Expand Up @@ -78,10 +78,9 @@ func TestUniqueVertexCacheHit(t *testing.T) {
id := ids.ID{2}
parentID := ids.ID{'p', 'a', 'r', 'e', 'n', 't'}
parentIDs := []ids.ID{parentID}
chainID := ids.ID{} // Same as chainID of serializer
height := uint64(1)
vtx, err := vertex.Build( // regular, non-stop vertex
chainID,
s.ChainID,
height,
parentIDs,
[][]byte{{0}},
Expand Down Expand Up @@ -153,10 +152,9 @@ func TestUniqueVertexCacheMiss(t *testing.T) {

parentID := uvtxParent.ID()
parentIDs := []ids.ID{parentID}
chainID := ids.ID{}
height := uint64(1)
innerVertex, err := vertex.Build( // regular, non-stop vertex
chainID,
s.ChainID,
height,
parentIDs,
[][]byte{txBytes},
Expand Down Expand Up @@ -259,16 +257,6 @@ func TestParseVertexWithIncorrectChainID(t *testing.T) {
func TestParseVertexWithInvalidTxs(t *testing.T) {
require := require.New(t)

chainID := ids.Empty
statelessVertex, err := vertex.Build( // regular, non-stop vertex
chainID,
0,
nil,
[][]byte{{1}},
)
require.NoError(err)
vtxBytes := statelessVertex.Bytes()

s := newTestSerializer(t, func(_ context.Context, b []byte) (snowstorm.Tx, error) {
switch {
case bytes.Equal(b, []byte{2}):
Expand All @@ -278,6 +266,15 @@ func TestParseVertexWithInvalidTxs(t *testing.T) {
}
})

statelessVertex, err := vertex.Build( // regular, non-stop vertex
s.ChainID,
0,
nil,
[][]byte{{1}},
)
require.NoError(err)
vtxBytes := statelessVertex.Bytes()

_, err = s.ParseVtx(context.Background(), vtxBytes)
require.ErrorIs(err, errUnknownTx)

Expand All @@ -289,7 +286,7 @@ func TestParseVertexWithInvalidTxs(t *testing.T) {
require.ErrorIs(err, errUnknownVertex)

childStatelessVertex, err := vertex.Build( // regular, non-stop vertex
chainID,
s.ChainID,
1,
[]ids.ID{id},
[][]byte{{2}},
Expand Down Expand Up @@ -323,14 +320,14 @@ func newTestUniqueVertex(
)
if !stopVertex {
vtx, err = vertex.Build(
ids.ID{},
s.ChainID,
uint64(1),
parentIDs,
txs,
)
} else {
vtx, err = vertex.BuildStopVertex(
ids.ID{},
s.ChainID,
uint64(1),
parentIDs,
)
Expand Down
18 changes: 9 additions & 9 deletions snow/engine/avalanche/vertex/stateless_vertex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestVertexVerify(t *testing.T) {
name: "valid vertex",
vertex: statelessVertex{innerStatelessVertex: innerStatelessVertex{
Version: 0,
ChainID: ids.ID{},
ChainID: ids.Empty,
Height: 0,
Epoch: 0,
ParentIDs: []ids.ID{},
Expand All @@ -51,7 +51,7 @@ func TestVertexVerify(t *testing.T) {
name: "invalid vertex epoch",
vertex: statelessVertex{innerStatelessVertex: innerStatelessVertex{
Version: 0,
ChainID: ids.ID{},
ChainID: ids.Empty,
Height: 0,
Epoch: 1,
ParentIDs: []ids.ID{},
Expand All @@ -63,7 +63,7 @@ func TestVertexVerify(t *testing.T) {
name: "too many vertex parents",
vertex: statelessVertex{innerStatelessVertex: innerStatelessVertex{
Version: 0,
ChainID: ids.ID{},
ChainID: ids.Empty,
Height: 0,
Epoch: 0,
ParentIDs: tooManyParents,
Expand All @@ -75,7 +75,7 @@ func TestVertexVerify(t *testing.T) {
name: "no vertex txs",
vertex: statelessVertex{innerStatelessVertex: innerStatelessVertex{
Version: 0,
ChainID: ids.ID{},
ChainID: ids.Empty,
Height: 0,
Epoch: 0,
ParentIDs: []ids.ID{},
Expand All @@ -87,7 +87,7 @@ func TestVertexVerify(t *testing.T) {
name: "too many vertex txs",
vertex: statelessVertex{innerStatelessVertex: innerStatelessVertex{
Version: 0,
ChainID: ids.ID{},
ChainID: ids.Empty,
Height: 0,
Epoch: 0,
ParentIDs: []ids.ID{},
Expand All @@ -99,7 +99,7 @@ func TestVertexVerify(t *testing.T) {
name: "unsorted vertex parents",
vertex: statelessVertex{innerStatelessVertex: innerStatelessVertex{
Version: 0,
ChainID: ids.ID{},
ChainID: ids.Empty,
Height: 0,
Epoch: 0,
ParentIDs: []ids.ID{{1}, {0}},
Expand All @@ -111,7 +111,7 @@ func TestVertexVerify(t *testing.T) {
name: "unsorted vertex txs",
vertex: statelessVertex{innerStatelessVertex: innerStatelessVertex{
Version: 0,
ChainID: ids.ID{},
ChainID: ids.Empty,
Height: 0,
Epoch: 0,
ParentIDs: []ids.ID{},
Expand All @@ -123,7 +123,7 @@ func TestVertexVerify(t *testing.T) {
name: "duplicate vertex parents",
vertex: statelessVertex{innerStatelessVertex: innerStatelessVertex{
Version: 0,
ChainID: ids.ID{},
ChainID: ids.Empty,
Height: 0,
Epoch: 0,
ParentIDs: []ids.ID{{0}, {0}},
Expand All @@ -135,7 +135,7 @@ func TestVertexVerify(t *testing.T) {
name: "duplicate vertex txs",
vertex: statelessVertex{innerStatelessVertex: innerStatelessVertex{
Version: 0,
ChainID: ids.ID{},
ChainID: ids.Empty,
Height: 0,
Epoch: 0,
ParentIDs: []ids.ID{},
Expand Down
2 changes: 1 addition & 1 deletion snow/engine/snowman/block/test_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (vm *TestVM) LastAccepted(ctx context.Context) (ids.ID, error) {
if vm.CantLastAccepted && vm.T != nil {
require.FailNow(vm.T, errLastAccepted.Error())
}
return ids.ID{}, errLastAccepted
return ids.Empty, errLastAccepted
}

func (vm *TestVM) GetBlockIDAtHeight(ctx context.Context, height uint64) (ids.ID, error) {
Expand Down
4 changes: 2 additions & 2 deletions snow/networking/handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func TestHandlerDropsTimedOutMessages(t *testing.T) {

nodeID := ids.EmptyNodeID
reqID := uint32(1)
chainID := ids.ID{}
chainID := ids.Empty
msg := Message{
InboundMessage: message.InboundGetAcceptedFrontier(chainID, reqID, 0*time.Second, nodeID),
EngineType: p2ppb.EngineType_ENGINE_TYPE_UNSPECIFIED,
Expand Down Expand Up @@ -237,7 +237,7 @@ func TestHandlerClosesOnError(t *testing.T) {
reqID := uint32(1)
deadline := time.Nanosecond
msg := Message{
InboundMessage: message.InboundGetAcceptedFrontier(ids.ID{}, reqID, deadline, nodeID),
InboundMessage: message.InboundGetAcceptedFrontier(ids.Empty, reqID, deadline, nodeID),
EngineType: p2ppb.EngineType_ENGINE_TYPE_UNSPECIFIED,
}
handler.Push(context.Background(), msg)
Expand Down
2 changes: 1 addition & 1 deletion snow/networking/router/chain_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func TestShutdownTimesOut(t *testing.T) {
shutdownFinished := make(chan struct{}, 1)

go func() {
chainID := ids.ID{}
chainID := ids.Empty
msg := handler.Message{
InboundMessage: message.InboundPullQuery(chainID, 1, time.Hour, ids.GenerateTestID(), 0, nodeID),
EngineType: p2ppb.EngineType_ENGINE_TYPE_UNSPECIFIED,
Expand Down
2 changes: 1 addition & 1 deletion snow/networking/timeout/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestManagerFire(t *testing.T) {

manager.RegisterRequest(
ids.EmptyNodeID,
ids.ID{},
ids.Empty,
true,
ids.RequestID{},
wg.Done,
Expand Down
Loading
Loading