forked from cerc-io/plugeth
all: make timestamp-based fork checks based on uint64 (#26474)
This PR changes the API so that uint64 is used for fork timestamps. It's a good choice because types.Header also uses uint64 for time. Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
co-authored by
Felix Lange
parent
59a48e0289
commit
2b57a27d9e
@@ -244,7 +244,7 @@ func gatherForks(config *params.ChainConfig) ([]uint64, []uint64) {
|
||||
// Gather all the fork block numbers via reflection
|
||||
kind := reflect.TypeOf(params.ChainConfig{})
|
||||
conf := reflect.ValueOf(config).Elem()
|
||||
|
||||
x := uint64(0)
|
||||
var (
|
||||
forksByBlock []uint64
|
||||
forksByTime []uint64
|
||||
@@ -257,15 +257,15 @@ func gatherForks(config *params.ChainConfig) ([]uint64, []uint64) {
|
||||
if !time && !strings.HasSuffix(field.Name, "Block") {
|
||||
continue
|
||||
}
|
||||
if field.Type != reflect.TypeOf(new(big.Int)) {
|
||||
continue
|
||||
}
|
||||
|
||||
// Extract the fork rule block number or timestamp and aggregate it
|
||||
rule := conf.Field(i).Interface().(*big.Int)
|
||||
if rule != nil {
|
||||
if time {
|
||||
forksByTime = append(forksByTime, rule.Uint64())
|
||||
} else {
|
||||
if field.Type == reflect.TypeOf(&x) {
|
||||
if rule := conf.Field(i).Interface().(*uint64); rule != nil {
|
||||
forksByTime = append(forksByTime, *rule)
|
||||
}
|
||||
}
|
||||
if field.Type == reflect.TypeOf(new(big.Int)) {
|
||||
if rule := conf.Field(i).Interface().(*big.Int); rule != nil {
|
||||
forksByBlock = append(forksByBlock, rule.Uint64())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package forkid
|
||||
import (
|
||||
"bytes"
|
||||
"math"
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
@@ -27,12 +26,14 @@ import (
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
)
|
||||
|
||||
func u64(val uint64) *uint64 { return &val }
|
||||
|
||||
// TestCreation tests that different genesis and fork rule combinations result in
|
||||
// the correct fork ID.
|
||||
func TestCreation(t *testing.T) {
|
||||
// Temporary non-existent scenario TODO(karalabe): delete when Shanghai is enabled
|
||||
timestampedConfig := *params.MainnetChainConfig
|
||||
timestampedConfig.ShanghaiTime = big.NewInt(1668000000)
|
||||
timestampedConfig.ShanghaiTime = u64(1668000000)
|
||||
|
||||
type testcase struct {
|
||||
head uint64
|
||||
@@ -201,7 +202,7 @@ func TestCreation(t *testing.T) {
|
||||
func TestValidation(t *testing.T) {
|
||||
// Temporary non-existent scenario TODO(karalabe): delete when Shanghai is enabled
|
||||
timestampedConfig := *params.MainnetChainConfig
|
||||
timestampedConfig.ShanghaiTime = big.NewInt(1668000000)
|
||||
timestampedConfig.ShanghaiTime = u64(1668000000)
|
||||
|
||||
tests := []struct {
|
||||
config *params.ChainConfig
|
||||
|
||||
Reference in New Issue
Block a user