Skip to content

Commit a4c1b5e

Browse files
authored
Merge pull request #179 from qianbin/reschedule-hotfix
FORK: reschedule the hotfix to block #1072000
2 parents cd8151e + b47538e commit a4c1b5e

File tree

9 files changed

+91
-48
lines changed

9 files changed

+91
-48
lines changed

chain/seeker.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,8 @@ func (s *Seeker) GetHeader(id thor.Bytes32) *block.Header {
5454
}
5555
return header
5656
}
57+
58+
// GenesisID get genesis block ID.
59+
func (s *Seeker) GenesisID() thor.Bytes32 {
60+
return s.chain.GenesisBlock().Header().ID()
61+
}

cmd/thor/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.3
1+
1.0.4

cmd/thor/must.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ func printStartupMessage(
291291
fmt.Printf(`Starting %v
292292
Network [ %v %v ]
293293
Best block [ %v #%v @%v ]
294+
Forks [ %v ]
294295
Master [ %v ]
295296
Beneficiary [ %v ]
296297
Instance dir [ %v ]
@@ -299,6 +300,7 @@ func printStartupMessage(
299300
common.MakeName("Thor", fullVersion()),
300301
gene.ID(), gene.Name(),
301302
bestBlock.Header().ID(), bestBlock.Header().Number(), time.Unix(int64(bestBlock.Header().Timestamp()), 0),
303+
thor.GetForkConfig(gene.ID()),
302304
master.Address(),
303305
func() string {
304306
if master.Beneficiary == nil {
@@ -346,11 +348,13 @@ func printSoloStartupMessage(
346348
info := fmt.Sprintf(`Starting %v
347349
Network [ %v %v ]
348350
Best block [ %v #%v @%v ]
351+
Forks [ %v ]
349352
Data dir [ %v ]
350353
API portal [ %v ]`,
351354
common.MakeName("Thor solo", fullVersion()),
352355
gene.ID(), gene.Name(),
353356
bestBlock.Header().ID(), bestBlock.Header().Number(), time.Unix(int64(bestBlock.Header().Timestamp()), 0),
357+
thor.GetForkConfig(gene.ID()),
354358
dataDir,
355359
apiURL)
356360

genesis/genesis.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,4 @@ func mustDecodeHex(str string) []byte {
6464
return data
6565
}
6666

67-
func mustParseAddress(str string) thor.Address {
68-
addr, err := thor.ParseAddress(str)
69-
if err != nil {
70-
panic(err)
71-
}
72-
return addr
73-
}
74-
75-
func mustParseBytes32(str string) thor.Bytes32 {
76-
b32, err := thor.ParseBytes32(str)
77-
if err != nil {
78-
panic(err)
79-
}
80-
return b32
81-
}
82-
8367
var emptyRuntimeBytecode = mustDecodeHex("6060604052600256")

genesis/mainnet.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,20 @@ func NewMainnet() *Genesis {
5252
// 21,046,908,616.5 x 4
5353
amount := new(big.Int).Mul(big.NewInt(210469086165), big.NewInt(1e17))
5454
tokenSupply.Add(tokenSupply, amount)
55-
state.SetBalance(mustParseAddress("0x137053dfbe6c0a43f915ad2efefefdcc2708e975"), amount)
56-
state.SetEnergy(mustParseAddress("0x137053dfbe6c0a43f915ad2efefefdcc2708e975"), &big.Int{}, launchTime)
55+
state.SetBalance(thor.MustParseAddress("0x137053dfbe6c0a43f915ad2efefefdcc2708e975"), amount)
56+
state.SetEnergy(thor.MustParseAddress("0x137053dfbe6c0a43f915ad2efefefdcc2708e975"), &big.Int{}, launchTime)
5757

5858
tokenSupply.Add(tokenSupply, amount)
59-
state.SetBalance(mustParseAddress("0xaf111431c1284a5e16d2eecd2daed133ce96820e"), amount)
60-
state.SetEnergy(mustParseAddress("0xaf111431c1284a5e16d2eecd2daed133ce96820e"), &big.Int{}, launchTime)
59+
state.SetBalance(thor.MustParseAddress("0xaf111431c1284a5e16d2eecd2daed133ce96820e"), amount)
60+
state.SetEnergy(thor.MustParseAddress("0xaf111431c1284a5e16d2eecd2daed133ce96820e"), &big.Int{}, launchTime)
6161

6262
tokenSupply.Add(tokenSupply, amount)
63-
state.SetBalance(mustParseAddress("0x997522a4274336f4b86af4a6ed9e45aedcc6d360"), amount)
64-
state.SetEnergy(mustParseAddress("0x997522a4274336f4b86af4a6ed9e45aedcc6d360"), &big.Int{}, launchTime)
63+
state.SetBalance(thor.MustParseAddress("0x997522a4274336f4b86af4a6ed9e45aedcc6d360"), amount)
64+
state.SetEnergy(thor.MustParseAddress("0x997522a4274336f4b86af4a6ed9e45aedcc6d360"), &big.Int{}, launchTime)
6565

6666
tokenSupply.Add(tokenSupply, amount)
67-
state.SetBalance(mustParseAddress("0x0bd7b06debd1522e75e4b91ff598f107fd826c8a"), amount)
68-
state.SetEnergy(mustParseAddress("0x0bd7b06debd1522e75e4b91ff598f107fd826c8a"), &big.Int{}, launchTime)
67+
state.SetBalance(thor.MustParseAddress("0x0bd7b06debd1522e75e4b91ff598f107fd826c8a"), amount)
68+
state.SetEnergy(thor.MustParseAddress("0x0bd7b06debd1522e75e4b91ff598f107fd826c8a"), &big.Int{}, launchTime)
6969

7070
builtin.Energy.Native(state, launchTime).SetInitialSupply(tokenSupply, energySupply)
7171
return nil
@@ -121,13 +121,13 @@ type approver struct {
121121

122122
func loadApprovers() []*approver {
123123
return []*approver{
124-
{mustParseAddress("0xb0f6d9933c1c2f4d891ca479343921f2d32e0fad"), "CY Cheung"},
125-
{mustParseAddress("0xda48cc4d23b41158e1294e0e4bcce8e9953cee26"), "George Kang"},
126-
{mustParseAddress("0xca7b45abe0d421e5628d2224bfe8fa6a6cf7c51b"), "Jay Zhang"},
127-
{mustParseAddress("0xa03f185f2a0def1efdd687ef3b96e404869d93de"), "Margaret Rui Zhu"},
128-
{mustParseAddress("0x74bac19f78369637db63f7496ecb5f88cc183672"), "Peter Zhou"},
129-
{mustParseAddress("0x5fefc7836af047c949d1fea72839823d2f06f7e3"), "Renato Grottola"},
130-
{mustParseAddress("0x7519874d0f7d31b5f0fd6f0429a4e5ece6f3fd49"), "Sunny Lu"},
124+
{thor.MustParseAddress("0xb0f6d9933c1c2f4d891ca479343921f2d32e0fad"), "CY Cheung"},
125+
{thor.MustParseAddress("0xda48cc4d23b41158e1294e0e4bcce8e9953cee26"), "George Kang"},
126+
{thor.MustParseAddress("0xca7b45abe0d421e5628d2224bfe8fa6a6cf7c51b"), "Jay Zhang"},
127+
{thor.MustParseAddress("0xa03f185f2a0def1efdd687ef3b96e404869d93de"), "Margaret Rui Zhu"},
128+
{thor.MustParseAddress("0x74bac19f78369637db63f7496ecb5f88cc183672"), "Peter Zhou"},
129+
{thor.MustParseAddress("0x5fefc7836af047c949d1fea72839823d2f06f7e3"), "Renato Grottola"},
130+
{thor.MustParseAddress("0x7519874d0f7d31b5f0fd6f0429a4e5ece6f3fd49"), "Sunny Lu"},
131131
}
132132
}
133133

@@ -239,9 +239,9 @@ func loadAuthorityNodes() []*authorityNode {
239239
candidates := make([]*authorityNode, 0, len(all))
240240
for _, item := range all {
241241
candidates = append(candidates, &authorityNode{
242-
masterAddress: mustParseAddress(item[0]),
243-
endorsorAddress: mustParseAddress(item[1]),
244-
identity: mustParseBytes32(item[2]),
242+
masterAddress: thor.MustParseAddress(item[0]),
243+
endorsorAddress: thor.MustParseAddress(item[1]),
244+
identity: thor.MustParseBytes32(item[2]),
245245
})
246246
}
247247
return candidates

runtime/runtime.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ type Output struct {
6868

6969
// Runtime bases on EVM and VeChain Thor builtins.
7070
type Runtime struct {
71-
vmConfig vm.Config
72-
seeker *chain.Seeker
73-
state *state.State
74-
ctx *xenv.BlockContext
71+
vmConfig vm.Config
72+
seeker *chain.Seeker
73+
state *state.State
74+
ctx *xenv.BlockContext
75+
forkConfig thor.ForkConfig
7576
}
7677

7778
// New create a Runtime object.
@@ -80,11 +81,18 @@ func New(
8081
state *state.State,
8182
ctx *xenv.BlockContext,
8283
) *Runtime {
83-
return &Runtime{
84+
rt := Runtime{
8485
seeker: seeker,
8586
state: state,
8687
ctx: ctx,
8788
}
89+
if seeker != nil {
90+
rt.forkConfig = thor.GetForkConfig(seeker.GenesisID())
91+
} else {
92+
// for genesis building stage
93+
rt.forkConfig = thor.NoFork
94+
}
95+
return &rt
8896
}
8997

9098
func (rt *Runtime) Seeker() *chain.Seeker { return rt.seeker }
@@ -118,7 +126,7 @@ func (rt *Runtime) newEVM(stateDB *statedb.StateDB, clauseIndex uint32, txCtx *x
118126
stateDB.SubBalance(common.Address(sender), amount)
119127
stateDB.AddBalance(common.Address(recipient), amount)
120128

121-
if rt.ctx.Number >= thor.FixTransferLogFork.BlockNumber {
129+
if rt.ctx.Number >= rt.forkConfig.FixTransferLog {
122130
// `amount` will be recycled by evm(OP_CALL) right after this function return,
123131
// which leads to incorrect transfer log.
124132
// Make a copy to prevent it.

thor/address.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ func ParseAddress(s string) (Address, error) {
8686
return addr, nil
8787
}
8888

89+
// MustParseAddress convert string presented address into Address type, panic on error.
90+
func MustParseAddress(s string) Address {
91+
addr, err := ParseAddress(s)
92+
if err != nil {
93+
panic(err)
94+
}
95+
return addr
96+
}
97+
8998
// BytesToAddress converts bytes slice into address.
9099
// If b is larger than address legnth, b will be cropped (from the left).
91100
// If b is smaller than address length, b will be extended (from the left).

thor/bytes32.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ func ParseBytes32(s string) (Bytes32, error) {
8585
return b, nil
8686
}
8787

88+
// MustParseBytes32 convert string presented into Bytes32 type, panic on error.
89+
func MustParseBytes32(s string) Bytes32 {
90+
b32, err := ParseBytes32(s)
91+
if err != nil {
92+
panic(err)
93+
}
94+
return b32
95+
}
96+
8897
// BytesToBytes32 converts bytes slice into Bytes32.
8998
// If b is larger than Bytes32 legnth, b will be cropped (from the left).
9099
// If b is smaller than Bytes32 length, b will be extended (from the left).

thor/fork_config.go

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
11
package thor
22

3+
import (
4+
"fmt"
5+
"math"
6+
)
7+
38
// ForkConfig config for a fork.
49
type ForkConfig struct {
5-
BlockNumber uint32
10+
FixTransferLog uint32
611
}
712

8-
// forks
9-
var (
10-
FixTransferLogFork = ForkConfig{
11-
BlockNumber: 1150000,
12-
}
13-
)
13+
func (fc ForkConfig) String() string {
14+
return fmt.Sprintf("FTRL: #%v", fc.FixTransferLog)
15+
}
16+
17+
// NoFork a special config without any forks.
18+
var NoFork = ForkConfig{
19+
FixTransferLog: math.MaxUint32,
20+
}
21+
22+
// for well-known networks
23+
var forkConfigs = map[Bytes32]ForkConfig{
24+
// mainnet
25+
MustParseBytes32("0x00000000851caf3cfdb6e899cf5958bfb1ac3413d346d43539627e6be7ec1b4a"): {
26+
FixTransferLog: 1072000,
27+
},
28+
// testnet
29+
MustParseBytes32("0x000000000b2bce3c70bc649a02749e8687721b09ed2e15997f466536b20bb127"): {
30+
FixTransferLog: 1080000,
31+
},
32+
}
33+
34+
// GetForkConfig get fork config for given genesis ID.
35+
func GetForkConfig(genesisID Bytes32) ForkConfig {
36+
return forkConfigs[genesisID]
37+
}

0 commit comments

Comments
 (0)