Skip to content

Commit bf62dfb

Browse files
committed
fix: add generics to ReadChainConfig and WriteChainConfig to eliminate coreth imports
1 parent e6f5461 commit bf62dfb

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

vms/evm/sync/customrawdb/accessors_metadata_ext.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import (
88
"fmt"
99
"time"
1010

11-
"github.com/ava-labs/coreth/params"
1211
"github.com/ava-labs/libevm/common"
1312
"github.com/ava-labs/libevm/core/rawdb"
1413
"github.com/ava-labs/libevm/ethdb"
1514
"github.com/ava-labs/libevm/log"
15+
"github.com/ava-labs/libevm/params"
1616
"github.com/ava-labs/libevm/rlp"
1717
)
1818

@@ -118,16 +118,16 @@ func ReadAcceptorTip(db ethdb.KeyValueReader) (common.Hash, error) {
118118
}
119119

120120
// ReadChainConfig retrieves the consensus settings based on the given genesis hash.
121-
func ReadChainConfig(db ethdb.KeyValueReader, hash common.Hash) *params.ChainConfig {
121+
// The provided [upgradeConfig] (any JSON-unmarshalable type) will be populated if present on disk.
122+
func ReadChainConfig[T any](db ethdb.KeyValueReader, hash common.Hash, upgradeConfig *T) *params.ChainConfig {
122123
config := rawdb.ReadChainConfig(db, hash)
123124

124125
upgrade, _ := db.Get(upgradeConfigKey(hash))
125126
if len(upgrade) == 0 {
126127
return config
127128
}
128129

129-
extra := params.GetExtra(config)
130-
if err := json.Unmarshal(upgrade, &extra.UpgradeConfig); err != nil {
130+
if err := json.Unmarshal(upgrade, upgradeConfig); err != nil {
131131
log.Error("Invalid upgrade config JSON", "err", err)
132132
return nil
133133
}
@@ -136,14 +136,14 @@ func ReadChainConfig(db ethdb.KeyValueReader, hash common.Hash) *params.ChainCon
136136
}
137137

138138
// WriteChainConfig writes the chain config settings to the database.
139-
func WriteChainConfig(db ethdb.KeyValueWriter, hash common.Hash, config *params.ChainConfig) {
139+
// The provided [upgradeConfig] (any JSON-marshalable type) will be stored alongside the chain config.
140+
func WriteChainConfig[T any](db ethdb.KeyValueWriter, hash common.Hash, config *params.ChainConfig, upgradeConfig T) {
140141
rawdb.WriteChainConfig(db, hash, config)
141142
if config == nil {
142143
return
143144
}
144145

145-
extra := params.GetExtra(config)
146-
data, err := json.Marshal(extra.UpgradeConfig)
146+
data, err := json.Marshal(upgradeConfig)
147147
if err != nil {
148148
log.Crit("Failed to JSON encode upgrade config", "err", err)
149149
}

0 commit comments

Comments
 (0)