Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
08481028
Unverified
Commit
08481028
authored
Dec 15, 2022
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core, les, params: add timestamp based fork compatibility checks
parent
a4e19c5c
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
272 additions
and
155 deletions
+272
-155
blockchain.go
core/blockchain.go
+5
-1
blockchain_test.go
core/blockchain_test.go
+1
-1
genesis.go
core/genesis.go
+5
-5
genesis_test.go
core/genesis_test.go
+4
-4
client.go
les/client.go
+5
-1
config.go
params/config.go
+189
-100
config_test.go
params/config_test.go
+63
-43
No files found.
core/blockchain.go
View file @
08481028
...
...
@@ -427,7 +427,11 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
// Rewind the chain in case of an incompatible config upgrade.
if
compat
,
ok
:=
genesisErr
.
(
*
params
.
ConfigCompatError
);
ok
{
log
.
Warn
(
"Rewinding chain to upgrade configuration"
,
"err"
,
compat
)
bc
.
SetHead
(
compat
.
RewindTo
)
if
compat
.
RewindToTime
>
0
{
log
.
Crit
(
"Timestamp based rewinds not implemented yet /sad"
)
}
else
{
bc
.
SetHead
(
compat
.
RewindToBlock
)
}
rawdb
.
WriteChainConfig
(
db
,
genesisHash
,
chainConfig
)
}
// Start tx indexer/unindexer if required.
...
...
core/blockchain_test.go
View file @
08481028
...
...
@@ -4275,7 +4275,7 @@ func TestEIP3651(t *testing.T) {
gspec
.
Config
.
BerlinBlock
=
common
.
Big0
gspec
.
Config
.
LondonBlock
=
common
.
Big0
gspec
.
Config
.
Shanghai
Block
=
common
.
Big0
gspec
.
Config
.
Shanghai
Time
=
common
.
Big0
signer
:=
types
.
LatestSigner
(
gspec
.
Config
)
_
,
blocks
,
_
:=
GenerateChainWithGenesis
(
gspec
,
engine
,
1
,
func
(
i
int
,
b
*
BlockGen
)
{
...
...
core/genesis.go
View file @
08481028
...
...
@@ -371,12 +371,12 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *trie.Database, gen
}
// Check config compatibility and write the config. Compatibility errors
// are returned to the caller unless we're already at block zero.
he
ight
:=
rawdb
.
ReadHeaderNumber
(
db
,
rawdb
.
ReadHeadHeaderHash
(
db
)
)
if
he
ight
==
nil
{
return
newcfg
,
stored
,
fmt
.
Errorf
(
"missing
block number for head header hash
"
)
he
ad
:=
rawdb
.
ReadHeadHeader
(
db
)
if
he
ad
==
nil
{
return
newcfg
,
stored
,
fmt
.
Errorf
(
"missing
head header
"
)
}
compatErr
:=
storedcfg
.
CheckCompatible
(
newcfg
,
*
height
)
if
compatErr
!=
nil
&&
*
height
!=
0
&&
compatErr
.
RewindTo
!=
0
{
compatErr
:=
storedcfg
.
CheckCompatible
(
newcfg
,
head
.
Number
.
Uint64
(),
head
.
Time
)
if
compatErr
!=
nil
&&
((
head
.
Number
.
Uint64
()
!=
0
&&
compatErr
.
RewindToBlock
!=
0
)
||
(
head
.
Time
!=
0
&&
compatErr
.
RewindToTime
!=
0
))
{
return
newcfg
,
stored
,
compatErr
}
// Don't overwrite if the old is identical to the new
...
...
core/genesis_test.go
View file @
08481028
...
...
@@ -132,10 +132,10 @@ func TestSetupGenesis(t *testing.T) {
wantHash
:
customghash
,
wantConfig
:
customg
.
Config
,
wantErr
:
&
params
.
ConfigCompatError
{
What
:
"Homestead fork block"
,
Stored
Config
:
big
.
NewInt
(
2
),
New
Config
:
big
.
NewInt
(
3
),
RewindTo
:
1
,
What
:
"Homestead fork block"
,
Stored
Block
:
big
.
NewInt
(
2
),
New
Block
:
big
.
NewInt
(
3
),
RewindTo
Block
:
1
,
},
},
}
...
...
les/client.go
View file @
08481028
...
...
@@ -179,7 +179,11 @@ func New(stack *node.Node, config *ethconfig.Config) (*LightEthereum, error) {
// Rewind the chain in case of an incompatible config upgrade.
if
compat
,
ok
:=
genesisErr
.
(
*
params
.
ConfigCompatError
);
ok
{
log
.
Warn
(
"Rewinding chain to upgrade configuration"
,
"err"
,
compat
)
leth
.
blockchain
.
SetHead
(
compat
.
RewindTo
)
if
compat
.
RewindToTime
>
0
{
log
.
Crit
(
"Timestamp based rewinds not implemented yet /sad"
)
}
else
{
leth
.
blockchain
.
SetHead
(
compat
.
RewindToBlock
)
}
rawdb
.
WriteChainConfig
(
chainDb
,
genesisHash
,
chainConfig
)
}
...
...
params/config.go
View file @
08481028
This diff is collapsed.
Click to expand it.
params/config_test.go
View file @
08481028
...
...
@@ -20,79 +20,99 @@ import (
"math/big"
"reflect"
"testing"
"time"
)
func
TestCheckCompatible
(
t
*
testing
.
T
)
{
type
test
struct
{
stored
,
new
*
ChainConfig
head
uint64
wantErr
*
ConfigCompatError
stored
,
new
*
ChainConfig
headBlock
uint64
headTimestamp
uint64
wantErr
*
ConfigCompatError
}
tests
:=
[]
test
{
{
stored
:
AllEthashProtocolChanges
,
new
:
AllEthashProtocolChanges
,
head
:
0
,
wantErr
:
nil
},
{
stored
:
AllEthashProtocolChanges
,
new
:
AllEthashProtocolChanges
,
head
:
100
,
wantErr
:
nil
},
{
stored
:
AllEthashProtocolChanges
,
new
:
AllEthashProtocolChanges
,
headBlock
:
0
,
headTimestamp
:
0
,
wantErr
:
nil
},
{
stored
:
AllEthashProtocolChanges
,
new
:
AllEthashProtocolChanges
,
headBlock
:
0
,
headTimestamp
:
uint64
(
time
.
Now
()
.
Unix
()),
wantErr
:
nil
},
{
stored
:
AllEthashProtocolChanges
,
new
:
AllEthashProtocolChanges
,
headBlock
:
100
,
wantErr
:
nil
},
{
stored
:
&
ChainConfig
{
EIP150Block
:
big
.
NewInt
(
10
)},
new
:
&
ChainConfig
{
EIP150Block
:
big
.
NewInt
(
20
)},
head
:
9
,
wantErr
:
nil
,
stored
:
&
ChainConfig
{
EIP150Block
:
big
.
NewInt
(
10
)},
new
:
&
ChainConfig
{
EIP150Block
:
big
.
NewInt
(
20
)},
head
Block
:
9
,
wantErr
:
nil
,
},
{
stored
:
AllEthashProtocolChanges
,
new
:
&
ChainConfig
{
HomesteadBlock
:
nil
},
head
:
3
,
stored
:
AllEthashProtocolChanges
,
new
:
&
ChainConfig
{
HomesteadBlock
:
nil
},
head
Block
:
3
,
wantErr
:
&
ConfigCompatError
{
What
:
"Homestead fork block"
,
Stored
Config
:
big
.
NewInt
(
0
),
New
Config
:
nil
,
RewindTo
:
0
,
What
:
"Homestead fork block"
,
Stored
Block
:
big
.
NewInt
(
0
),
New
Block
:
nil
,
RewindTo
Block
:
0
,
},
},
{
stored
:
AllEthashProtocolChanges
,
new
:
&
ChainConfig
{
HomesteadBlock
:
big
.
NewInt
(
1
)},
head
:
3
,
stored
:
AllEthashProtocolChanges
,
new
:
&
ChainConfig
{
HomesteadBlock
:
big
.
NewInt
(
1
)},
head
Block
:
3
,
wantErr
:
&
ConfigCompatError
{
What
:
"Homestead fork block"
,
Stored
Config
:
big
.
NewInt
(
0
),
New
Config
:
big
.
NewInt
(
1
),
RewindTo
:
0
,
What
:
"Homestead fork block"
,
Stored
Block
:
big
.
NewInt
(
0
),
New
Block
:
big
.
NewInt
(
1
),
RewindTo
Block
:
0
,
},
},
{
stored
:
&
ChainConfig
{
HomesteadBlock
:
big
.
NewInt
(
30
),
EIP150Block
:
big
.
NewInt
(
10
)},
new
:
&
ChainConfig
{
HomesteadBlock
:
big
.
NewInt
(
25
),
EIP150Block
:
big
.
NewInt
(
20
)},
head
:
25
,
stored
:
&
ChainConfig
{
HomesteadBlock
:
big
.
NewInt
(
30
),
EIP150Block
:
big
.
NewInt
(
10
)},
new
:
&
ChainConfig
{
HomesteadBlock
:
big
.
NewInt
(
25
),
EIP150Block
:
big
.
NewInt
(
20
)},
head
Block
:
25
,
wantErr
:
&
ConfigCompatError
{
What
:
"EIP150 fork block"
,
Stored
Config
:
big
.
NewInt
(
10
),
New
Config
:
big
.
NewInt
(
20
),
RewindTo
:
9
,
What
:
"EIP150 fork block"
,
Stored
Block
:
big
.
NewInt
(
10
),
New
Block
:
big
.
NewInt
(
20
),
RewindTo
Block
:
9
,
},
},
{
stored
:
&
ChainConfig
{
ConstantinopleBlock
:
big
.
NewInt
(
30
)},
new
:
&
ChainConfig
{
ConstantinopleBlock
:
big
.
NewInt
(
30
),
PetersburgBlock
:
big
.
NewInt
(
30
)},
head
:
40
,
wantErr
:
nil
,
stored
:
&
ChainConfig
{
ConstantinopleBlock
:
big
.
NewInt
(
30
)},
new
:
&
ChainConfig
{
ConstantinopleBlock
:
big
.
NewInt
(
30
),
PetersburgBlock
:
big
.
NewInt
(
30
)},
head
Block
:
40
,
wantErr
:
nil
,
},
{
stored
:
&
ChainConfig
{
ConstantinopleBlock
:
big
.
NewInt
(
30
)},
new
:
&
ChainConfig
{
ConstantinopleBlock
:
big
.
NewInt
(
30
),
PetersburgBlock
:
big
.
NewInt
(
31
)},
head
:
40
,
stored
:
&
ChainConfig
{
ConstantinopleBlock
:
big
.
NewInt
(
30
)},
new
:
&
ChainConfig
{
ConstantinopleBlock
:
big
.
NewInt
(
30
),
PetersburgBlock
:
big
.
NewInt
(
31
)},
head
Block
:
40
,
wantErr
:
&
ConfigCompatError
{
What
:
"Petersburg fork block"
,
StoredConfig
:
nil
,
NewConfig
:
big
.
NewInt
(
31
),
RewindTo
:
30
,
What
:
"Petersburg fork block"
,
StoredBlock
:
nil
,
NewBlock
:
big
.
NewInt
(
31
),
RewindToBlock
:
30
,
},
},
{
stored
:
&
ChainConfig
{
ShanghaiTime
:
big
.
NewInt
(
10
)},
new
:
&
ChainConfig
{
ShanghaiTime
:
big
.
NewInt
(
20
)},
headTimestamp
:
9
,
wantErr
:
nil
,
},
{
stored
:
&
ChainConfig
{
ShanghaiTime
:
big
.
NewInt
(
10
)},
new
:
&
ChainConfig
{
ShanghaiTime
:
big
.
NewInt
(
20
)},
headTimestamp
:
25
,
wantErr
:
&
ConfigCompatError
{
What
:
"Shanghai fork timestamp"
,
StoredTime
:
big
.
NewInt
(
10
),
NewTime
:
big
.
NewInt
(
20
),
RewindToTime
:
9
,
},
},
}
for
_
,
test
:=
range
tests
{
err
:=
test
.
stored
.
CheckCompatible
(
test
.
new
,
test
.
head
)
err
:=
test
.
stored
.
CheckCompatible
(
test
.
new
,
test
.
head
Block
,
test
.
headTimestamp
)
if
!
reflect
.
DeepEqual
(
err
,
test
.
wantErr
)
{
t
.
Errorf
(
"error mismatch:
\n
stored: %v
\n
new: %v
\n
head
: %v
\n
err: %v
\n
want: %v"
,
test
.
stored
,
test
.
new
,
test
.
head
,
err
,
test
.
wantErr
)
t
.
Errorf
(
"error mismatch:
\n
stored: %v
\n
new: %v
\n
head
Block: %v
\n
headTimestamp: %v
\n
err: %v
\n
want: %v"
,
test
.
stored
,
test
.
new
,
test
.
headBlock
,
test
.
headTimestamp
,
err
,
test
.
wantErr
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment