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

Cleanup ID initialization #2690

Merged
merged 1 commit into from
Feb 1, 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
9 changes: 9 additions & 0 deletions ids/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ func FromString(idStr string) (ID, error) {
return ToID(bytes)
}

// FromStringOrPanic is the same as FromString, but will panic on error
func FromStringOrPanic(idStr string) ID {
id, err := FromString(idStr)
if err != nil {
panic(err)
}
return id
}

func (id ID) MarshalJSON() ([]byte, error) {
str, err := cb58.Encode(id[:])
if err != nil {
Expand Down
36 changes: 12 additions & 24 deletions version/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,18 @@ var (
constants.MainnetID: time.Date(2023, time.April, 25, 15, 0, 0, 0, time.UTC),
constants.FujiID: time.Date(2023, time.April, 6, 15, 0, 0, 0, time.UTC),
}
CortinaXChainStopVertexID map[uint32]ids.ID
CortinaXChainStopVertexID = map[uint32]ids.ID{
// The mainnet stop vertex is well known. It can be verified on any
// fully synced node by looking at the parentID of the genesis block.
//
// Ref: https://subnets.avax.network/x-chain/block/0
constants.MainnetID: ids.FromStringOrPanic("jrGWDh5Po9FMj54depyunNixpia5PN4aAYxfmNzU8n752Rjga"),
// The fuji stop vertex is well known. It can be verified on any fully
// synced node by looking at the parentID of the genesis block.
//
// Ref: https://subnets-test.avax.network/x-chain/block/0
constants.FujiID: ids.FromStringOrPanic("2D1cmbiG36BqQMRyHt4kFhWarmatA1ighSpND3FeFgz3vFVtCZ"),
}

// TODO: update this before release
DurangoTimes = map[uint32]time.Time{
Expand Down Expand Up @@ -151,29 +162,6 @@ func init() {
}
RPCChainVMProtocolCompatibility[rpcChainVMProtocol] = versions
}

// The mainnet stop vertex is well known. It can be verified on any fully
// synced node by looking at the parentID of the genesis block.
//
// Ref: https://subnets.avax.network/x-chain/block/0
mainnetXChainStopVertexID, err := ids.FromString("jrGWDh5Po9FMj54depyunNixpia5PN4aAYxfmNzU8n752Rjga")
if err != nil {
panic(err)
}

// The fuji stop vertex is well known. It can be verified on any fully
// synced node by looking at the parentID of the genesis block.
//
// Ref: https://subnets-test.avax.network/x-chain/block/0
fujiXChainStopVertexID, err := ids.FromString("2D1cmbiG36BqQMRyHt4kFhWarmatA1ighSpND3FeFgz3vFVtCZ")
if err != nil {
panic(err)
}

CortinaXChainStopVertexID = map[uint32]ids.ID{
constants.MainnetID: mainnetXChainStopVertexID,
constants.FujiID: fujiXChainStopVertexID,
}
}

func GetApricotPhase1Time(networkID uint32) time.Time {
Expand Down
17 changes: 2 additions & 15 deletions vms/proposervm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,14 @@ var (
_ block.StateSyncableVM = (*VM)(nil)

// TODO: remove after the X-chain supports height indexing.
mainnetXChainID ids.ID
fujiXChainID ids.ID
mainnetXChainID = ids.FromStringOrPanic("2oYMBNV4eNHyqk2fjjV5nVQLDbtmNJzq5s3qs3Lo6ftnC6FByM")
fujiXChainID = ids.FromStringOrPanic("2JVSBoinj9C2J33VntvzYtVJNZdN2NKiwwKjcumHUWEb5DbBrm")

dbPrefix = []byte("proposervm")

errHeightIndexInvalidWhilePruning = errors.New("height index invalid while pruning old blocks")
)

func init() {
var err error
mainnetXChainID, err = ids.FromString("2oYMBNV4eNHyqk2fjjV5nVQLDbtmNJzq5s3qs3Lo6ftnC6FByM")
if err != nil {
panic(err)
}

fujiXChainID, err = ids.FromString("2JVSBoinj9C2J33VntvzYtVJNZdN2NKiwwKjcumHUWEb5DbBrm")
if err != nil {
panic(err)
}
}

func cachedBlockSize(_ ids.ID, blk snowman.Block) int {
return ids.IDLen + len(blk.Bytes()) + constants.PointerOverhead
}
Expand Down
Loading