Skip to content

Commit

Permalink
Merge pull request #179 from qianbin/reschedule-hotfix
Browse files Browse the repository at this point in the history
FORK: reschedule the hotfix to block #1072000
  • Loading branch information
qianbin authored Oct 26, 2018
2 parents cd8151e + b47538e commit a4c1b5e
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 48 deletions.
5 changes: 5 additions & 0 deletions chain/seeker.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ func (s *Seeker) GetHeader(id thor.Bytes32) *block.Header {
}
return header
}

// GenesisID get genesis block ID.
func (s *Seeker) GenesisID() thor.Bytes32 {
return s.chain.GenesisBlock().Header().ID()
}
2 changes: 1 addition & 1 deletion cmd/thor/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.3
1.0.4
4 changes: 4 additions & 0 deletions cmd/thor/must.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ func printStartupMessage(
fmt.Printf(`Starting %v
Network [ %v %v ]
Best block [ %v #%v @%v ]
Forks [ %v ]
Master [ %v ]
Beneficiary [ %v ]
Instance dir [ %v ]
Expand All @@ -299,6 +300,7 @@ func printStartupMessage(
common.MakeName("Thor", fullVersion()),
gene.ID(), gene.Name(),
bestBlock.Header().ID(), bestBlock.Header().Number(), time.Unix(int64(bestBlock.Header().Timestamp()), 0),
thor.GetForkConfig(gene.ID()),
master.Address(),
func() string {
if master.Beneficiary == nil {
Expand Down Expand Up @@ -346,11 +348,13 @@ func printSoloStartupMessage(
info := fmt.Sprintf(`Starting %v
Network [ %v %v ]
Best block [ %v #%v @%v ]
Forks [ %v ]
Data dir [ %v ]
API portal [ %v ]`,
common.MakeName("Thor solo", fullVersion()),
gene.ID(), gene.Name(),
bestBlock.Header().ID(), bestBlock.Header().Number(), time.Unix(int64(bestBlock.Header().Timestamp()), 0),
thor.GetForkConfig(gene.ID()),
dataDir,
apiURL)

Expand Down
16 changes: 0 additions & 16 deletions genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,4 @@ func mustDecodeHex(str string) []byte {
return data
}

func mustParseAddress(str string) thor.Address {
addr, err := thor.ParseAddress(str)
if err != nil {
panic(err)
}
return addr
}

func mustParseBytes32(str string) thor.Bytes32 {
b32, err := thor.ParseBytes32(str)
if err != nil {
panic(err)
}
return b32
}

var emptyRuntimeBytecode = mustDecodeHex("6060604052600256")
36 changes: 18 additions & 18 deletions genesis/mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ func NewMainnet() *Genesis {
// 21,046,908,616.5 x 4
amount := new(big.Int).Mul(big.NewInt(210469086165), big.NewInt(1e17))
tokenSupply.Add(tokenSupply, amount)
state.SetBalance(mustParseAddress("0x137053dfbe6c0a43f915ad2efefefdcc2708e975"), amount)
state.SetEnergy(mustParseAddress("0x137053dfbe6c0a43f915ad2efefefdcc2708e975"), &big.Int{}, launchTime)
state.SetBalance(thor.MustParseAddress("0x137053dfbe6c0a43f915ad2efefefdcc2708e975"), amount)
state.SetEnergy(thor.MustParseAddress("0x137053dfbe6c0a43f915ad2efefefdcc2708e975"), &big.Int{}, launchTime)

tokenSupply.Add(tokenSupply, amount)
state.SetBalance(mustParseAddress("0xaf111431c1284a5e16d2eecd2daed133ce96820e"), amount)
state.SetEnergy(mustParseAddress("0xaf111431c1284a5e16d2eecd2daed133ce96820e"), &big.Int{}, launchTime)
state.SetBalance(thor.MustParseAddress("0xaf111431c1284a5e16d2eecd2daed133ce96820e"), amount)
state.SetEnergy(thor.MustParseAddress("0xaf111431c1284a5e16d2eecd2daed133ce96820e"), &big.Int{}, launchTime)

tokenSupply.Add(tokenSupply, amount)
state.SetBalance(mustParseAddress("0x997522a4274336f4b86af4a6ed9e45aedcc6d360"), amount)
state.SetEnergy(mustParseAddress("0x997522a4274336f4b86af4a6ed9e45aedcc6d360"), &big.Int{}, launchTime)
state.SetBalance(thor.MustParseAddress("0x997522a4274336f4b86af4a6ed9e45aedcc6d360"), amount)
state.SetEnergy(thor.MustParseAddress("0x997522a4274336f4b86af4a6ed9e45aedcc6d360"), &big.Int{}, launchTime)

tokenSupply.Add(tokenSupply, amount)
state.SetBalance(mustParseAddress("0x0bd7b06debd1522e75e4b91ff598f107fd826c8a"), amount)
state.SetEnergy(mustParseAddress("0x0bd7b06debd1522e75e4b91ff598f107fd826c8a"), &big.Int{}, launchTime)
state.SetBalance(thor.MustParseAddress("0x0bd7b06debd1522e75e4b91ff598f107fd826c8a"), amount)
state.SetEnergy(thor.MustParseAddress("0x0bd7b06debd1522e75e4b91ff598f107fd826c8a"), &big.Int{}, launchTime)

builtin.Energy.Native(state, launchTime).SetInitialSupply(tokenSupply, energySupply)
return nil
Expand Down Expand Up @@ -121,13 +121,13 @@ type approver struct {

func loadApprovers() []*approver {
return []*approver{
{mustParseAddress("0xb0f6d9933c1c2f4d891ca479343921f2d32e0fad"), "CY Cheung"},
{mustParseAddress("0xda48cc4d23b41158e1294e0e4bcce8e9953cee26"), "George Kang"},
{mustParseAddress("0xca7b45abe0d421e5628d2224bfe8fa6a6cf7c51b"), "Jay Zhang"},
{mustParseAddress("0xa03f185f2a0def1efdd687ef3b96e404869d93de"), "Margaret Rui Zhu"},
{mustParseAddress("0x74bac19f78369637db63f7496ecb5f88cc183672"), "Peter Zhou"},
{mustParseAddress("0x5fefc7836af047c949d1fea72839823d2f06f7e3"), "Renato Grottola"},
{mustParseAddress("0x7519874d0f7d31b5f0fd6f0429a4e5ece6f3fd49"), "Sunny Lu"},
{thor.MustParseAddress("0xb0f6d9933c1c2f4d891ca479343921f2d32e0fad"), "CY Cheung"},
{thor.MustParseAddress("0xda48cc4d23b41158e1294e0e4bcce8e9953cee26"), "George Kang"},
{thor.MustParseAddress("0xca7b45abe0d421e5628d2224bfe8fa6a6cf7c51b"), "Jay Zhang"},
{thor.MustParseAddress("0xa03f185f2a0def1efdd687ef3b96e404869d93de"), "Margaret Rui Zhu"},
{thor.MustParseAddress("0x74bac19f78369637db63f7496ecb5f88cc183672"), "Peter Zhou"},
{thor.MustParseAddress("0x5fefc7836af047c949d1fea72839823d2f06f7e3"), "Renato Grottola"},
{thor.MustParseAddress("0x7519874d0f7d31b5f0fd6f0429a4e5ece6f3fd49"), "Sunny Lu"},
}
}

Expand Down Expand Up @@ -239,9 +239,9 @@ func loadAuthorityNodes() []*authorityNode {
candidates := make([]*authorityNode, 0, len(all))
for _, item := range all {
candidates = append(candidates, &authorityNode{
masterAddress: mustParseAddress(item[0]),
endorsorAddress: mustParseAddress(item[1]),
identity: mustParseBytes32(item[2]),
masterAddress: thor.MustParseAddress(item[0]),
endorsorAddress: thor.MustParseAddress(item[1]),
identity: thor.MustParseBytes32(item[2]),
})
}
return candidates
Expand Down
20 changes: 14 additions & 6 deletions runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ type Output struct {

// Runtime bases on EVM and VeChain Thor builtins.
type Runtime struct {
vmConfig vm.Config
seeker *chain.Seeker
state *state.State
ctx *xenv.BlockContext
vmConfig vm.Config
seeker *chain.Seeker
state *state.State
ctx *xenv.BlockContext
forkConfig thor.ForkConfig
}

// New create a Runtime object.
Expand All @@ -80,11 +81,18 @@ func New(
state *state.State,
ctx *xenv.BlockContext,
) *Runtime {
return &Runtime{
rt := Runtime{
seeker: seeker,
state: state,
ctx: ctx,
}
if seeker != nil {
rt.forkConfig = thor.GetForkConfig(seeker.GenesisID())
} else {
// for genesis building stage
rt.forkConfig = thor.NoFork
}
return &rt
}

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

if rt.ctx.Number >= thor.FixTransferLogFork.BlockNumber {
if rt.ctx.Number >= rt.forkConfig.FixTransferLog {
// `amount` will be recycled by evm(OP_CALL) right after this function return,
// which leads to incorrect transfer log.
// Make a copy to prevent it.
Expand Down
9 changes: 9 additions & 0 deletions thor/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ func ParseAddress(s string) (Address, error) {
return addr, nil
}

// MustParseAddress convert string presented address into Address type, panic on error.
func MustParseAddress(s string) Address {
addr, err := ParseAddress(s)
if err != nil {
panic(err)
}
return addr
}

// BytesToAddress converts bytes slice into address.
// If b is larger than address legnth, b will be cropped (from the left).
// If b is smaller than address length, b will be extended (from the left).
Expand Down
9 changes: 9 additions & 0 deletions thor/bytes32.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ func ParseBytes32(s string) (Bytes32, error) {
return b, nil
}

// MustParseBytes32 convert string presented into Bytes32 type, panic on error.
func MustParseBytes32(s string) Bytes32 {
b32, err := ParseBytes32(s)
if err != nil {
panic(err)
}
return b32
}

// BytesToBytes32 converts bytes slice into Bytes32.
// If b is larger than Bytes32 legnth, b will be cropped (from the left).
// If b is smaller than Bytes32 length, b will be extended (from the left).
Expand Down
38 changes: 31 additions & 7 deletions thor/fork_config.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
package thor

import (
"fmt"
"math"
)

// ForkConfig config for a fork.
type ForkConfig struct {
BlockNumber uint32
FixTransferLog uint32
}

// forks
var (
FixTransferLogFork = ForkConfig{
BlockNumber: 1150000,
}
)
func (fc ForkConfig) String() string {
return fmt.Sprintf("FTRL: #%v", fc.FixTransferLog)
}

// NoFork a special config without any forks.
var NoFork = ForkConfig{
FixTransferLog: math.MaxUint32,
}

// for well-known networks
var forkConfigs = map[Bytes32]ForkConfig{
// mainnet
MustParseBytes32("0x00000000851caf3cfdb6e899cf5958bfb1ac3413d346d43539627e6be7ec1b4a"): {
FixTransferLog: 1072000,
},
// testnet
MustParseBytes32("0x000000000b2bce3c70bc649a02749e8687721b09ed2e15997f466536b20bb127"): {
FixTransferLog: 1080000,
},
}

// GetForkConfig get fork config for given genesis ID.
func GetForkConfig(genesisID Bytes32) ForkConfig {
return forkConfigs[genesisID]
}

0 comments on commit a4c1b5e

Please sign in to comment.