Skip to content

Commit 833f70b

Browse files
authored
xin-203 fix wrong config hash and update v2 params on mainnet (ethereum#109)
* fix wrong config hash and update v2 params on mainnet * update config and all the test * hard code binary into code * add default config for testing * update test timestamp
1 parent 90395f5 commit 833f70b

File tree

8 files changed

+236
-238
lines changed

8 files changed

+236
-238
lines changed

cmd/XDC/consolecmd_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestConsoleWelcome(t *testing.T) {
5252
XDC.SetTemplateFunc("goarch", func() string { return runtime.GOARCH })
5353
XDC.SetTemplateFunc("gover", runtime.Version)
5454
XDC.SetTemplateFunc("XDCver", func() string { return params.Version })
55-
XDC.SetTemplateFunc("niltime", func() string { return time.Unix(1544771829, 0).Format(time.RFC1123) })
55+
XDC.SetTemplateFunc("niltime", func() string { return time.Unix(1559211559, 0).Format(time.RFC1123) })
5656
XDC.SetTemplateFunc("apis", func() string { return ipcAPIs })
5757

5858
// Verify the actual welcome message to the required template
@@ -137,7 +137,7 @@ func testAttachWelcome(t *testing.T, XDC *testXDC, endpoint, apis string) {
137137
attach.SetTemplateFunc("gover", runtime.Version)
138138
attach.SetTemplateFunc("XDCver", func() string { return params.Version })
139139
attach.SetTemplateFunc("etherbase", func() string { return XDC.Etherbase })
140-
attach.SetTemplateFunc("niltime", func() string { return time.Unix(1544771829, 0).Format(time.RFC1123) })
140+
attach.SetTemplateFunc("niltime", func() string { return time.Unix(1559211559, 0).Format(time.RFC1123) })
141141
attach.SetTemplateFunc("ipc", func() bool { return strings.HasPrefix(endpoint, "ipc") })
142142
attach.SetTemplateFunc("datadir", func() string { return XDC.Datadir })
143143
attach.SetTemplateFunc("apis", func() string { return apis })

consensus/XDPoS/XDPoS.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,14 @@ func New(config *params.XDPoSConfig, db ethdb.Database) *XDPoS {
8080
config.Epoch = utils.EpochLength
8181
}
8282

83+
// For testing and testing project, default to mainnet config
84+
if config.V2 == nil {
85+
config.V2 = params.XDPoSV2Config
86+
}
87+
88+
log.Info("xdc config loading", "config", config)
89+
8390
waitPeriodCh := make(chan int)
84-
// TODO: This shall be configurable or replaced
85-
config.V2 = params.DevnetXDPoSV2Config
8691

8792
// Allocate the snapshot caches and create the engine
8893
signingTxsCache, _ := lru.New(utils.BlockSignersCacheLimit)

core/genesis.go

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,11 @@ func SetupGenesisBlock(db ethdb.Database, genesis *Genesis) (*params.ChainConfig
188188
}
189189
return newcfg, stored, err
190190
}
191-
// Special case: don't change the existing config of a non-mainnet chain if no new
191+
192+
// Special case: don't change the existing config of a non-xinfin chain if no new
192193
// config is supplied. These chains would get AllProtocolChanges (and a compat error)
193194
// if we just continued here.
194-
if genesis == nil && stored != params.MainnetGenesisHash {
195+
if genesis == nil && newcfg == params.AllEthashProtocolChanges {
195196
return storedcfg, stored, nil
196197
}
197198

@@ -211,12 +212,19 @@ func SetupGenesisBlock(db ethdb.Database, genesis *Genesis) (*params.ChainConfig
211212
func (g *Genesis) configOrDefault(ghash common.Hash) *params.ChainConfig {
212213
switch {
213214
case g != nil:
215+
log.Info("[configOrDefault] load orignal config", "hash", ghash)
214216
return g.Config
215-
case ghash == params.MainnetGenesisHash:
217+
case ghash == params.XDCMainnetGenesisHash:
218+
log.Info("[configOrDefault] load mainnetconfig")
216219
return params.XDCMainnetChainConfig
217220
case ghash == params.TestnetGenesisHash:
221+
log.Info("[configOrDefault] load TestnetChainConfig")
218222
return params.TestnetChainConfig
223+
case ghash == params.DevnetGenesisHash:
224+
log.Info("[configOrDefault] load DevnetChainConfig")
225+
return params.DevnetChainConfig
219226
default:
227+
log.Info("[configOrDefault] load AllEthashProtocolChanges", "hash", ghash)
220228
return params.AllEthashProtocolChanges
221229
}
222230
}
@@ -312,26 +320,31 @@ func GenesisBlockForTesting(db ethdb.Database, addr common.Address, balance *big
312320

313321
// DefaultGenesisBlock returns the Ethereum main net genesis block.
314322
func DefaultGenesisBlock() *Genesis {
323+
config := params.XDCMainnetChainConfig
324+
config.XDPoS.V2 = nil
315325
return &Genesis{
316-
Config: params.XDCMainnetChainConfig,
326+
Config: config,
317327
Nonce: 0,
318-
ExtraData: hexutil.MustDecode("0x00000000000000000000000000000000000000000000000000000000000000001b82c4bf317fcafe3d77e8b444c82715d216afe845b7bd987fa22c9bac89b71f0ded03f6e150ba31ad670b2b166684657ffff95f4810380ae7381e9bce41231d5dd8cdd7499e418b648c00af75d184a2f9aba09a6fa4a46fb1a6a3919b027d9cac5aa6890000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
328+
ExtraData: hexutil.MustDecode("0x000000000000000000000000000000000000000000000000000000000000000025c65b4b379ac37cf78357c4915f73677022eaffc7d49d0a2cf198deebd6ce581af465944ec8b2bbcfccdea1006a5cfa7d9484b5b293b46964c265c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
319329
GasLimit: 4700000,
320330
Difficulty: big.NewInt(1),
321-
Alloc: DecodeMainnet(),
322-
Timestamp: 1544771829,
331+
Alloc: DecodeAllocJson(XDCAllocData),
332+
Timestamp: 1559211559,
323333
}
324334
}
325335

326336
// DefaultTestnetGenesisBlock returns the Ropsten network genesis block.
327337
func DefaultTestnetGenesisBlock() *Genesis {
338+
config := params.TestnetChainConfig
339+
config.XDPoS.V2 = nil
328340
return &Genesis{
329341
Config: params.TestnetChainConfig,
330-
Nonce: 66,
331-
ExtraData: hexutil.MustDecode("0x3535353535353535353535353535353535353535353535353535353535353535"),
332-
GasLimit: 16777216,
333-
Difficulty: big.NewInt(1048576),
334-
Alloc: decodePrealloc(testnetAllocData),
342+
Nonce: 0,
343+
ExtraData: hexutil.MustDecode("0x00000000000000000000000000000000000000000000000000000000000000003ea0a3555f9b1de983572bff6444aeb1899ec58c4f7900282f3d371d585ab1361205b0940ab1789c942a5885a8844ee5587c8ac5e371fc39ffe618960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
344+
GasLimit: 4700000,
345+
Difficulty: big.NewInt(1),
346+
Alloc: DecodeAllocJson(XDCTestAllocData),
347+
Timestamp: 1560417871,
335348
}
336349
}
337350

@@ -386,8 +399,8 @@ func decodePrealloc(data string) GenesisAlloc {
386399
return ga
387400
}
388401

389-
func DecodeMainnet() GenesisAlloc {
390-
mainnetAlloc := GenesisAlloc{}
391-
json.Unmarshal([]byte(XDCAllocData), &mainnetAlloc)
392-
return mainnetAlloc
402+
func DecodeAllocJson(s string) GenesisAlloc {
403+
alloc := GenesisAlloc{}
404+
json.Unmarshal([]byte(s), &alloc)
405+
return alloc
393406
}

core/genesis_alloc.go

Lines changed: 3 additions & 1 deletion
Large diffs are not rendered by default.

core/genesis_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
package core
1818

1919
import (
20-
"github.com/XinFinOrg/XDPoSChain/core/rawdb"
2120
"math/big"
2221
"reflect"
2322
"testing"
2423

25-
"github.com/XinFinOrg/XDPoSChain/common"
2624
"github.com/XinFinOrg/XDPoSChain/consensus/ethash"
25+
"github.com/XinFinOrg/XDPoSChain/core/rawdb"
2726
"github.com/XinFinOrg/XDPoSChain/core/vm"
27+
28+
"github.com/XinFinOrg/XDPoSChain/common"
2829
"github.com/XinFinOrg/XDPoSChain/ethdb"
2930
"github.com/XinFinOrg/XDPoSChain/params"
3031
"github.com/davecgh/go-spew/spew"

0 commit comments

Comments
 (0)