Skip to content

Commit

Permalink
fix: genesis block hash (#20)
Browse files Browse the repository at this point in the history
Signed-off-by: Jingfu Wang <jingfu.wang@coinbase.com>
  • Loading branch information
GeekArthur authored Feb 8, 2023
1 parent b76d2df commit aa61638
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
57 changes: 31 additions & 26 deletions pkg/config/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,40 @@ import (
func LoadConfiguration() (*configuration.Configuration, error) {
config := &configuration.Configuration{}

mode := os.Getenv(ModeEnv)
modeValue := configuration.Mode(mode)

switch modeValue {
// Mode
modeValue := os.Getenv(ModeEnv)
mode := configuration.Mode(modeValue)
switch mode {
case Online:
config.Mode = Online
case Offline:
config.Mode = Offline
case "":
return nil, fmt.Errorf("%s must be populated", ModeEnv)
return nil, fmt.Errorf("%s must be populated", mode)
default:
return nil, fmt.Errorf("%s is not a valid mode", modeValue)
return nil, fmt.Errorf("%s is not a valid mode", mode)
}

// Blockchain and Network
blockchain := os.Getenv(BlockchainEnv)
if blockchain == "" {
blockchain = DefaultBlockchain
}
network := os.Getenv(NetworkEnv)
config.Network = &RosettaTypes.NetworkIdentifier{
Blockchain: blockchain,
Network: network,
}

networkValue := os.Getenv(NetworkEnv)
transitionHash := os.Getenv(TransitionBlockHashEnv)
transitionBlockHash := &RosettaTypes.BlockIdentifier{
// Genesis block
genesisBlockHash := os.Getenv(GenesisBlockHashEnv)
genesisBlockIdentifier := &RosettaTypes.BlockIdentifier{
Index: GenesisBlockIndex,
Hash: transitionHash,
Hash: genesisBlockHash,
}
config.GenesisBlockIdentifier = genesisBlockIdentifier

// Chain config
chainConfigJson := os.Getenv(ChainConfigEnv)
if file, err := os.ReadFile(chainConfigJson); err == nil {
// if the envvar points to a file, read it; otherwise the envvar contents is expected to be JSON
Expand All @@ -52,48 +60,44 @@ func LoadConfiguration() (*configuration.Configuration, error) {
if chainConfigJson == "" {
return nil, fmt.Errorf("%s not set", ChainConfigEnv)
}

chainConfig := &params.ChainConfig{}
err := json.Unmarshal([]byte(chainConfigJson), &chainConfig)
if err != nil {
return nil, fmt.Errorf("unable to parse chain config: %w", err)
}

config.Network = &RosettaTypes.NetworkIdentifier{
Blockchain: blockchain,
Network: networkValue,
}
config.GenesisBlockIdentifier = transitionBlockHash
config.ChainConfig = chainConfig

// Geth URL
config.GethURL = DefaultGethURL
envGethURL := os.Getenv(GethEnv)
if len(envGethURL) > 0 {
gethURL := os.Getenv(GethEnv)
if len(gethURL) > 0 {
config.RemoteGeth = true
config.GethURL = envGethURL
config.GethURL = gethURL
}

// Skip geth admin
config.SkipGethAdmin = false
envSkipGethAdmin := os.Getenv(SkipGethAdminEnv)
if len(envSkipGethAdmin) > 0 {
val, err := strconv.ParseBool(envSkipGethAdmin)
skipGethAdmin := os.Getenv(SkipGethAdminEnv)
if len(skipGethAdmin) > 0 {
val, err := strconv.ParseBool(skipGethAdmin)
if err != nil {
return nil, fmt.Errorf("unable to parse SKIP_GETH_ADMIN %s: %w", envSkipGethAdmin, err)
return nil, fmt.Errorf("unable to parse SKIP_GETH_ADMIN %s: %w", skipGethAdmin, err)
}
config.SkipGethAdmin = val
}

// Port
portValue := os.Getenv(PortEnv)
if len(portValue) == 0 {
return nil, errors.New("PORT must be populated")
}

port, err := strconv.Atoi(portValue)
if err != nil || len(portValue) == 0 || port <= 0 {
return nil, fmt.Errorf("unable to parse port %s: %w", portValue, err)
}
config.Port = port

// Filter tokens
filterTokens := true
filterTokensStr := os.Getenv(FilterTokensEnv)
if len(filterTokensStr) > 0 {
Expand All @@ -103,7 +107,7 @@ func LoadConfiguration() (*configuration.Configuration, error) {
}
}

// Graceful tokenlist unmarshalling
// Token list
tokenListJsonFilename := os.Getenv(TokenListEnv)
tokenListJsonFile, err := ReadTokenConfig(tokenListJsonFilename)
if err != nil {
Expand All @@ -114,6 +118,7 @@ func LoadConfiguration() (*configuration.Configuration, error) {
return nil, err
}

// Rosetta
config.RosettaCfg = configuration.RosettaConfig{
SupportRewardTx: false,
TraceType: configuration.GethNativeTrace,
Expand Down
6 changes: 3 additions & 3 deletions pkg/config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ const (
// read to determine network.
NetworkEnv = "NETWORK"

// TransitionBlockHashEnv is the environment variable
// from which to read the transition block hash.
TransitionBlockHashEnv = "TRANSITION_BLOCK_HASH"
// GenesisBlockHashEnv is the environment variable
// from which to read the genesis block hash.
GenesisBlockHashEnv = "GENESIS_BLOCK_HASH"

// ChainConfigEnv is the environment variable from
// which to read the chain configuration, defined as
Expand Down

0 comments on commit aa61638

Please sign in to comment.