Skip to content

Commit 19ec675

Browse files
NathanBSCqdm12
authored andcommitted
params: print time value instead of pointer in ConfigCompatError (ethereum#29514)
1 parent c78db42 commit 19ec675

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

params/config.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ func newTimestampCompatError(what string, storedtime, newtime *uint64) *ConfigCo
880880
NewTime: newtime,
881881
RewindToTime: 0,
882882
}
883-
if rew != nil {
883+
if rew != nil && *rew != 0 {
884884
err.RewindToTime = *rew - 1
885885
}
886886
return err
@@ -890,7 +890,15 @@ func (err *ConfigCompatError) Error() string {
890890
if err.StoredBlock != nil {
891891
return fmt.Sprintf("mismatching %s in database (have block %d, want block %d, rewindto block %d)", err.What, err.StoredBlock, err.NewBlock, err.RewindToBlock)
892892
}
893-
return fmt.Sprintf("mismatching %s in database (have timestamp %d, want timestamp %d, rewindto timestamp %d)", err.What, err.StoredTime, err.NewTime, err.RewindToTime)
893+
894+
if err.StoredTime == nil && err.NewTime == nil {
895+
return ""
896+
} else if err.StoredTime == nil && err.NewTime != nil {
897+
return fmt.Sprintf("mismatching %s in database (have timestamp nil, want timestamp %d, rewindto timestamp %d)", err.What, *err.NewTime, err.RewindToTime)
898+
} else if err.StoredTime != nil && err.NewTime == nil {
899+
return fmt.Sprintf("mismatching %s in database (have timestamp %d, want timestamp nil, rewindto timestamp %d)", err.What, *err.StoredTime, err.RewindToTime)
900+
}
901+
return fmt.Sprintf("mismatching %s in database (have timestamp %d, want timestamp %d, rewindto timestamp %d)", err.What, *err.StoredTime, *err.NewTime, err.RewindToTime)
894902
}
895903

896904
// Rules wraps ChainConfig and is merely syntactic sugar or can be used for functions

params/config_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"time"
2424

2525
"github.com/ava-labs/libevm/common/math"
26+
"github.com/stretchr/testify/require"
2627
)
2728

2829
func TestCheckCompatible(t *testing.T) {
@@ -137,3 +138,20 @@ func TestConfigRules(t *testing.T) {
137138
t.Errorf("expected %v to be shanghai", stamp)
138139
}
139140
}
141+
142+
func TestTimestampCompatError(t *testing.T) {
143+
require.Equal(t, new(ConfigCompatError).Error(), "")
144+
145+
errWhat := "Shanghai fork timestamp"
146+
require.Equal(t, newTimestampCompatError(errWhat, nil, newUint64(1681338455)).Error(),
147+
"mismatching Shanghai fork timestamp in database (have timestamp nil, want timestamp 1681338455, rewindto timestamp 1681338454)")
148+
149+
require.Equal(t, newTimestampCompatError(errWhat, newUint64(1681338455), nil).Error(),
150+
"mismatching Shanghai fork timestamp in database (have timestamp 1681338455, want timestamp nil, rewindto timestamp 1681338454)")
151+
152+
require.Equal(t, newTimestampCompatError(errWhat, newUint64(1681338455), newUint64(600624000)).Error(),
153+
"mismatching Shanghai fork timestamp in database (have timestamp 1681338455, want timestamp 600624000, rewindto timestamp 600623999)")
154+
155+
require.Equal(t, newTimestampCompatError(errWhat, newUint64(0), newUint64(1681338455)).Error(),
156+
"mismatching Shanghai fork timestamp in database (have timestamp 0, want timestamp 1681338455, rewindto timestamp 0)")
157+
}

0 commit comments

Comments
 (0)