aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cmd/gdex/main.go1
-rw-r--r--cmd/utils/flags.go14
-rw-r--r--dex/backend.go7
-rw-r--r--dex/handler.go6
-rw-r--r--dex/helper_test.go9
-rw-r--r--dex/peer.go10
-rw-r--r--dex/protocol.go3
-rw-r--r--dex/protocol_test.go10
-rw-r--r--params/config.go14
-rw-r--r--test/genesis.json1
-rwxr-xr-xtest/run_test.sh3
11 files changed, 42 insertions, 36 deletions
diff --git a/cmd/gdex/main.go b/cmd/gdex/main.go
index 8e08e2d77..a2597c098 100644
--- a/cmd/gdex/main.go
+++ b/cmd/gdex/main.go
@@ -98,7 +98,6 @@ var (
utils.MaxPeersFlag,
utils.MaxPendingPeersFlag,
utils.BlockProposerEnabledFlag,
- utils.ConsensusDMomentFlag,
utils.MiningEnabledFlag,
utils.MinerThreadsFlag,
utils.MinerLegacyThreadsFlag,
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index bfe565c30..d26bbb065 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -326,10 +326,6 @@ var (
Name: "bp",
Usage: "Enable block proposer mode (node set)",
}
- ConsensusDMomentFlag = cli.Uint64Flag{
- Name: "dmoment",
- Usage: "Set the DMoment of DEXON Consensus (unix timestamp)",
- }
// Miner settings
MiningEnabledFlag = cli.BoolFlag{
Name: "mine",
@@ -1288,16 +1284,6 @@ func SetDexConfig(ctx *cli.Context, stack *node.Node, cfg *dex.Config) {
if gen := ctx.GlobalInt(TrieCacheGenFlag.Name); gen > 0 {
state.MaxTrieCacheGen = uint16(gen)
}
- if ctx.GlobalIsSet(ConsensusDMomentFlag.Name) {
- cfg.DMoment = int64(ctx.GlobalUint64(ConsensusDMomentFlag.Name))
- } else {
- // TODO(jimmy): default DMoment should be set based on networkId.
- now := time.Now()
- cfg.DMoment = time.Date(
- now.Year(), now.Month(), now.Day(),
- now.Hour(), now.Minute(), (now.Second()/5+1)*5,
- 0, now.Location()).Unix()
- }
// Set indexer config.
setIndexerConfig(ctx, cfg)
diff --git a/dex/backend.go b/dex/backend.go
index 88cfa3033..c75fdfa29 100644
--- a/dex/backend.go
+++ b/dex/backend.go
@@ -162,8 +162,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Dexon, error) {
// Set config fetcher so engine can fetch current system configuration from state.
engine.SetGovStateFetcher(dex.governance)
- dMoment := time.Unix(config.DMoment, int64(0))
- log.Info("DEXON Consensus DMoment", "time", dMoment)
+ dMoment := time.Unix(int64(chainConfig.DMoment), 0)
// Force starting with full sync mode if this node is a bootstrap proposer.
if config.BlockProposerEnabled && dMoment.After(time.Now()) {
@@ -171,8 +170,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Dexon, error) {
}
pm, err := NewProtocolManager(dex.chainConfig, config.SyncMode,
- config.NetworkId, dex.eventMux, dex.txPool, dex.engine, dex.blockchain,
- chainDb, config.BlockProposerEnabled, dex.governance, dex.app)
+ config.NetworkId, chainConfig.DMoment, dex.eventMux, dex.txPool, dex.engine,
+ dex.blockchain, chainDb, config.BlockProposerEnabled, dex.governance, dex.app)
if err != nil {
return nil, err
}
diff --git a/dex/handler.go b/dex/handler.go
index a097605c0..a3fbf2ba9 100644
--- a/dex/handler.go
+++ b/dex/handler.go
@@ -91,6 +91,7 @@ func errResp(code errCode, format string, v ...interface{}) error {
type ProtocolManager struct {
networkID uint64
+ dMoment uint64
fastSync uint32 // Flag whether fast sync is enabled (gets disabled if we already have blocks)
acceptTxs uint32 // Flag whether we're considered synchronised (enables transaction processing)
@@ -147,13 +148,14 @@ type ProtocolManager struct {
// with the Ethereum network.
func NewProtocolManager(
config *params.ChainConfig, mode downloader.SyncMode, networkID uint64,
- mux *event.TypeMux, txpool txPool, engine consensus.Engine,
+ dMoment uint64, mux *event.TypeMux, txpool txPool, engine consensus.Engine,
blockchain *core.BlockChain, chaindb ethdb.Database,
isBlockProposer bool, gov governance, app dexconApp) (*ProtocolManager, error) {
tab := newNodeTable()
// Create the protocol manager with the base fields
manager := &ProtocolManager{
networkID: networkID,
+ dMoment: dMoment,
eventMux: mux,
txpool: txpool,
nodeTable: tab,
@@ -343,7 +345,7 @@ func (pm *ProtocolManager) handle(p *peer) error {
hash = head.Hash()
number = head.Number.Uint64()
)
- if err := p.Handshake(pm.networkID, number, hash, genesis.Hash()); err != nil {
+ if err := p.Handshake(pm.networkID, pm.dMoment, number, hash, genesis.Hash()); err != nil {
p.Log().Debug("Ethereum handshake failed", "err", err)
return err
}
diff --git a/dex/helper_test.go b/dex/helper_test.go
index 86a901cc2..e3d6aa3b7 100644
--- a/dex/helper_test.go
+++ b/dex/helper_test.go
@@ -46,6 +46,8 @@ var (
testBank = crypto.PubkeyToAddress(testBankKey.PublicKey)
)
+const dMoment = 123456
+
// testP2PServer is a fake, helper p2p server for testing purposes.
type testP2PServer struct {
mu sync.Mutex
@@ -134,7 +136,7 @@ func newTestProtocolManager(mode downloader.SyncMode, blocks int, generator func
notarySetFunc: func(uint64, uint32) (map[string]struct{}, error) { return nil, nil },
}
- pm, err := NewProtocolManager(gspec.Config, mode, DefaultConfig.NetworkId, evmux, &testTxPool{added: newtx}, engine, blockchain, db, true, tgov, &testApp{})
+ pm, err := NewProtocolManager(gspec.Config, mode, DefaultConfig.NetworkId, dMoment, evmux, &testTxPool{added: newtx}, engine, blockchain, db, true, tgov, &testApp{})
if err != nil {
return nil, nil, err
}
@@ -275,17 +277,18 @@ func newTestPeer(name string, version int, pm *ProtocolManager, shake bool) (*te
head = pm.blockchain.CurrentHeader()
number = head.Number.Uint64()
)
- tp.handshake(nil, number, head.Hash(), genesis.Hash())
+ tp.handshake(nil, dMoment, number, head.Hash(), genesis.Hash())
}
return tp, errc
}
// handshake simulates a trivial handshake that expects the same state from the
// remote side as we are simulating locally.
-func (p *testPeer) handshake(t *testing.T, number uint64, head common.Hash, genesis common.Hash) {
+func (p *testPeer) handshake(t *testing.T, dMoment uint64, number uint64, head common.Hash, genesis common.Hash) {
msg := &statusData{
ProtocolVersion: uint32(p.version),
NetworkId: DefaultConfig.NetworkId,
+ DMoment: uint64(dMoment),
Number: number,
CurrentBlock: head,
GenesisBlock: genesis,
diff --git a/dex/peer.go b/dex/peer.go
index 295c5c400..0a67db688 100644
--- a/dex/peer.go
+++ b/dex/peer.go
@@ -631,7 +631,7 @@ func (p *peer) RequestReceipts(hashes []common.Hash) error {
// Handshake executes the eth protocol handshake, negotiating version number,
// network IDs, difficulties, head and genesis blocks.
-func (p *peer) Handshake(network uint64, number uint64, head common.Hash, genesis common.Hash) error {
+func (p *peer) Handshake(network uint64, dMoment uint64, number uint64, head common.Hash, genesis common.Hash) error {
// Send out own handshake in a new thread
errc := make(chan error, 2)
var status statusData // safe to read after two values have been received from errc
@@ -640,13 +640,14 @@ func (p *peer) Handshake(network uint64, number uint64, head common.Hash, genesi
errc <- p2p.Send(p.rw, StatusMsg, &statusData{
ProtocolVersion: uint32(p.version),
NetworkId: network,
+ DMoment: dMoment,
Number: number,
CurrentBlock: head,
GenesisBlock: genesis,
})
}()
go func() {
- errc <- p.readStatus(network, &status, genesis)
+ errc <- p.readStatus(network, dMoment, &status, genesis)
}()
timeout := time.NewTimer(handshakeTimeout)
defer timeout.Stop()
@@ -664,7 +665,7 @@ func (p *peer) Handshake(network uint64, number uint64, head common.Hash, genesi
return nil
}
-func (p *peer) readStatus(network uint64, status *statusData, genesis common.Hash) (err error) {
+func (p *peer) readStatus(network uint64, dMoment uint64, status *statusData, genesis common.Hash) (err error) {
msg, err := p.rw.ReadMsg()
if err != nil {
return err
@@ -685,6 +686,9 @@ func (p *peer) readStatus(network uint64, status *statusData, genesis common.Has
if status.NetworkId != network {
return errResp(ErrNetworkIdMismatch, "%d (!= %d)", status.NetworkId, network)
}
+ if status.DMoment != dMoment {
+ return errResp(ErrDMomentMismatch, "%d (!= %d)", status.DMoment, dMoment)
+ }
if int(status.ProtocolVersion) != p.version {
return errResp(ErrProtocolVersionMismatch, "%d (!= %d)", status.ProtocolVersion, p.version)
}
diff --git a/dex/protocol.go b/dex/protocol.go
index c6b4c37c4..9244b8bb7 100644
--- a/dex/protocol.go
+++ b/dex/protocol.go
@@ -106,6 +106,7 @@ const (
ErrInvalidMsgCode
ErrProtocolVersionMismatch
ErrNetworkIdMismatch
+ ErrDMomentMismatch
ErrGenesisBlockMismatch
ErrNoStatusMsg
ErrExtraStatusMsg
@@ -123,6 +124,7 @@ var errorToString = map[int]string{
ErrInvalidMsgCode: "Invalid message code",
ErrProtocolVersionMismatch: "Protocol version mismatch",
ErrNetworkIdMismatch: "NetworkId mismatch",
+ ErrDMomentMismatch: "DMoment mismatch",
ErrGenesisBlockMismatch: "Genesis block mismatch",
ErrNoStatusMsg: "No status message",
ErrExtraStatusMsg: "Extra status message",
@@ -177,6 +179,7 @@ type p2pServer interface {
type statusData struct {
ProtocolVersion uint32
NetworkId uint64
+ DMoment uint64
Number uint64
CurrentBlock common.Hash
GenesisBlock common.Hash
diff --git a/dex/protocol_test.go b/dex/protocol_test.go
index e9bd4e110..5c68785e8 100644
--- a/dex/protocol_test.go
+++ b/dex/protocol_test.go
@@ -69,15 +69,19 @@ func testStatusMsgErrors(t *testing.T, protocol int) {
wantError: errResp(ErrNoStatusMsg, "first msg has code 2 (!= 0)"),
},
{
- code: StatusMsg, data: statusData{10, DefaultConfig.NetworkId, number, head.Hash(), genesis.Hash()},
+ code: StatusMsg, data: statusData{10, DefaultConfig.NetworkId, dMoment, number, head.Hash(), genesis.Hash()},
wantError: errResp(ErrProtocolVersionMismatch, "10 (!= %d)", protocol),
},
{
- code: StatusMsg, data: statusData{uint32(protocol), 999, number, head.Hash(), genesis.Hash()},
+ code: StatusMsg, data: statusData{uint32(protocol), 999, dMoment, number, head.Hash(), genesis.Hash()},
wantError: errResp(ErrNetworkIdMismatch, "999 (!= 237)"),
},
{
- code: StatusMsg, data: statusData{uint32(protocol), DefaultConfig.NetworkId, number, head.Hash(), common.Hash{3}},
+ code: StatusMsg, data: statusData{uint32(protocol), DefaultConfig.NetworkId, 123450, number, head.Hash(), genesis.Hash()},
+ wantError: errResp(ErrDMomentMismatch, "123450 (!= %d)", dMoment),
+ },
+ {
+ code: StatusMsg, data: statusData{uint32(protocol), DefaultConfig.NetworkId, dMoment, number, head.Hash(), common.Hash{3}},
wantError: errResp(ErrGenesisBlockMismatch, "0300000000000000 (!= %x)", genesis.Hash().Bytes()[:8]),
},
}
diff --git a/params/config.go b/params/config.go
index fd7bac275..843ffdc92 100644
--- a/params/config.go
+++ b/params/config.go
@@ -41,6 +41,7 @@ var (
// MainnetChainConfig is the chain parameters to run a node on the main network.
MainnetChainConfig = &ChainConfig{
ChainID: big.NewInt(237),
+ DMoment: 0,
HomesteadBlock: big.NewInt(0),
DAOForkBlock: big.NewInt(0),
DAOForkSupport: true,
@@ -89,6 +90,7 @@ var (
// TestnetChainConfig contains the chain parameters to run a node on the Taiwan test network.
TestnetChainConfig = &ChainConfig{
ChainID: big.NewInt(238),
+ DMoment: 1547462100,
HomesteadBlock: big.NewInt(0),
DAOForkBlock: nil,
DAOForkSupport: true,
@@ -127,6 +129,7 @@ var (
// TaipeiChainConfig contains the chain parameters to run a node on the Taipei test network.
TaipeiChainConfig = &ChainConfig{
ChainID: big.NewInt(239),
+ DMoment: 0,
HomesteadBlock: big.NewInt(0),
DAOForkBlock: nil,
DAOForkSupport: true,
@@ -176,23 +179,24 @@ var (
//
// This configuration is intentionally not using keyed fields to force anyone
// adding flags to the config to also have to set these fields.
- AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil, nil}
+ AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), 0, big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil, nil}
// AllCliqueProtocolChanges contains every protocol change (EIPs) introduced
// and accepted by the Ethereum core developers into the Clique consensus.
//
// This configuration is intentionally not using keyed fields to force anyone
// adding flags to the config to also have to set these fields.
- AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}, nil}
+ AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), 0, big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}, nil}
- AllDexconProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, new(DexconConfig)}
+ AllDexconProtocolChanges = &ChainConfig{big.NewInt(1337), 0, big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, new(DexconConfig)}
- TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil, nil}
+ TestChainConfig = &ChainConfig{big.NewInt(1), 0, big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil, nil}
TestRules = TestChainConfig.Rules(new(big.Int))
// Ethereum MainnetChainConfig is the chain parameters to run a node on the main network.
EthereumMainnetChainConfig = &ChainConfig{
ChainID: big.NewInt(1),
+ DMoment: 0,
HomesteadBlock: big.NewInt(1150000),
DAOForkBlock: big.NewInt(1920000),
DAOForkSupport: true,
@@ -208,6 +212,7 @@ var (
// Ethereum TestnetChainConfig contains the chain parameters to run a node on the Ropsten test network.
EthereumTestnetChainConfig = &ChainConfig{
ChainID: big.NewInt(3),
+ DMoment: 0,
HomesteadBlock: big.NewInt(0),
DAOForkBlock: nil,
DAOForkSupport: true,
@@ -240,6 +245,7 @@ type TrustedCheckpoint struct {
// set of configuration options.
type ChainConfig struct {
ChainID *big.Int `json:"chainId"` // chainId identifies the current chain and is used for replay protection
+ DMoment uint64 `json:"dMoment"` // dMoment which indicate the starting time of the network
HomesteadBlock *big.Int `json:"homesteadBlock,omitempty"` // Homestead switch block (nil = no fork, 0 = already homestead)
diff --git a/test/genesis.json b/test/genesis.json
index ce3526883..efa2727ad 100644
--- a/test/genesis.json
+++ b/test/genesis.json
@@ -1,6 +1,7 @@
{
"config": {
"chainId": 237,
+ "dMoment": 1547480026,
"homesteadBlock": 0,
"daoForkBlock": 0,
"daoForkSupport": true,
diff --git a/test/run_test.sh b/test/run_test.sh
index 71b2715dd..a42e27142 100755
--- a/test/run_test.sh
+++ b/test/run_test.sh
@@ -22,6 +22,7 @@ rm -f log-latest
ln -s $logsdir log-latest
let dmoment=`date +%s`+7
+sed -i "s/\"dMoment\": [0-9]\+,/\"dMoment\": $dmoment,/g" $GENESIS
# A standalone RPC server for accepting RPC requests.
datadir=$PWD/Dexon.rpc
@@ -37,7 +38,6 @@ $GDEX \
--ws --wsapi=eth,net,web3,debug \
--wsaddr=0.0.0.0 --wsport=8546 \
--wsorigins='*' --rpcvhosts='*' --rpccorsdomain="*" \
- --dmoment=$dmoment \
> $logsdir/gdex.rpc.log 2>&1 &
# Nodes
@@ -57,7 +57,6 @@ for i in $(seq 0 3); do
--ws --wsapi=eth,net,web3,debug \
--wsaddr=0.0.0.0 --wsport=$((8548 + $i * 2)) \
--wsorigins='*' --rpcvhosts='*' --rpccorsdomain="*" \
- --dmoment=$dmoment \
--pprof --pprofaddr=localhost --pprofport=$((6060 + $i)) \
> $logsdir/gdex.$i.log 2>&1 &
done