diff options
author | Wei-Ning Huang <w@dexon.org> | 2019-03-17 10:43:10 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-12 17:27:23 +0800 |
commit | 5f64e1d10d620a8a299ff3a40695f26107f157c5 (patch) | |
tree | e28e2bf073ac7da8417e5b0789d2d0713e240ae7 /dex | |
parent | 9493109f2be4507605e6b17e406bf8fd147ab3c8 (diff) | |
download | go-tangerine-5f64e1d10d620a8a299ff3a40695f26107f157c5.tar go-tangerine-5f64e1d10d620a8a299ff3a40695f26107f157c5.tar.gz go-tangerine-5f64e1d10d620a8a299ff3a40695f26107f157c5.tar.bz2 go-tangerine-5f64e1d10d620a8a299ff3a40695f26107f157c5.tar.lz go-tangerine-5f64e1d10d620a8a299ff3a40695f26107f157c5.tar.xz go-tangerine-5f64e1d10d620a8a299ff3a40695f26107f157c5.tar.zst go-tangerine-5f64e1d10d620a8a299ff3a40695f26107f157c5.zip |
core: fill in genesis timstamp and remove dMoment from protocol handshake (#263)
Fill in dmoment as genesis block timestamp. This allow us to remove
dMoment check from protocol handshake since genesis block hash itself
will protect us against different dMoment.
Diffstat (limited to 'dex')
-rw-r--r-- | dex/backend.go | 4 | ||||
-rw-r--r-- | dex/handler.go | 6 | ||||
-rw-r--r-- | dex/helper_test.go | 9 | ||||
-rw-r--r-- | dex/peer.go | 10 | ||||
-rw-r--r-- | dex/protocol.go | 3 | ||||
-rw-r--r-- | dex/protocol_test.go | 10 |
6 files changed, 13 insertions, 29 deletions
diff --git a/dex/backend.go b/dex/backend.go index 6ee1a5fa1..0f68163c0 100644 --- a/dex/backend.go +++ b/dex/backend.go @@ -172,8 +172,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Dexon, error) { } pm, err := NewProtocolManager(dex.chainConfig, config.SyncMode, - config.NetworkId, chainConfig.DMoment, dex.eventMux, dex.txPool, dex.engine, - dex.blockchain, chainDb, config.BlockProposerEnabled, dex.governance, dex.app) + config.NetworkId, 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 76219c747..ea04e6fbc 100644 --- a/dex/handler.go +++ b/dex/handler.go @@ -97,7 +97,6 @@ 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) @@ -158,14 +157,13 @@ type ProtocolManager struct { // with the Ethereum network. func NewProtocolManager( config *params.ChainConfig, mode downloader.SyncMode, networkID uint64, - dMoment uint64, mux *event.TypeMux, txpool txPool, engine consensus.Engine, + 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, @@ -355,7 +353,7 @@ func (pm *ProtocolManager) handle(p *peer) error { hash = head.Hash() number = head.Number.Uint64() ) - if err := p.Handshake(pm.networkID, pm.dMoment, number, hash, genesis.Hash()); err != nil { + if err := p.Handshake(pm.networkID, 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 c8bf62a6b..4f5541052 100644 --- a/dex/helper_test.go +++ b/dex/helper_test.go @@ -46,8 +46,6 @@ 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 @@ -135,7 +133,7 @@ func newTestProtocolManager(mode downloader.SyncMode, blocks int, generator func notarySetFunc: func(uint64) (map[string]struct{}, error) { return nil, nil }, } - pm, err := NewProtocolManager(gspec.Config, mode, DefaultConfig.NetworkId, dMoment, evmux, &testTxPool{added: newtx}, engine, blockchain, db, true, tgov, &testApp{}) + pm, err := NewProtocolManager(gspec.Config, mode, DefaultConfig.NetworkId, evmux, &testTxPool{added: newtx}, engine, blockchain, db, true, tgov, &testApp{}) if err != nil { return nil, nil, err } @@ -275,18 +273,17 @@ func newTestPeer(name string, version int, pm *ProtocolManager, shake bool) (*te head = pm.blockchain.CurrentHeader() number = head.Number.Uint64() ) - tp.handshake(nil, dMoment, number, head.Hash(), genesis.Hash()) + tp.handshake(nil, 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, dMoment uint64, number uint64, head common.Hash, genesis common.Hash) { +func (p *testPeer) handshake(t *testing.T, 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 6a5786e1f..e015ed9e5 100644 --- a/dex/peer.go +++ b/dex/peer.go @@ -669,7 +669,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, dMoment uint64, number uint64, head common.Hash, genesis common.Hash) error { +func (p *peer) Handshake(network 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 @@ -678,14 +678,13 @@ func (p *peer) Handshake(network uint64, dMoment uint64, number uint64, head com 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, dMoment, &status, genesis) + errc <- p.readStatus(network, &status, genesis) }() timeout := time.NewTimer(handshakeTimeout) defer timeout.Stop() @@ -703,7 +702,7 @@ func (p *peer) Handshake(network uint64, dMoment uint64, number uint64, head com return nil } -func (p *peer) readStatus(network uint64, dMoment uint64, status *statusData, genesis common.Hash) (err error) { +func (p *peer) readStatus(network uint64, status *statusData, genesis common.Hash) (err error) { msg, err := p.rw.ReadMsg() if err != nil { return err @@ -724,9 +723,6 @@ func (p *peer) readStatus(network uint64, dMoment uint64, status *statusData, ge 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 afa6e560d..e09829cc8 100644 --- a/dex/protocol.go +++ b/dex/protocol.go @@ -106,7 +106,6 @@ const ( ErrInvalidMsgCode ErrProtocolVersionMismatch ErrNetworkIdMismatch - ErrDMomentMismatch ErrGenesisBlockMismatch ErrNoStatusMsg ErrExtraStatusMsg @@ -129,7 +128,6 @@ 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", @@ -180,7 +178,6 @@ 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 422824559..23b2c4248 100644 --- a/dex/protocol_test.go +++ b/dex/protocol_test.go @@ -69,19 +69,15 @@ func testStatusMsgErrors(t *testing.T, protocol int) { wantError: errResp(ErrNoStatusMsg, "first msg has code 2 (!= 0)"), }, { - code: StatusMsg, data: statusData{10, DefaultConfig.NetworkId, dMoment, number, head.Hash(), genesis.Hash()}, + code: StatusMsg, data: statusData{10, DefaultConfig.NetworkId, number, head.Hash(), genesis.Hash()}, wantError: errResp(ErrProtocolVersionMismatch, "10 (!= %d)", protocol), }, { - code: StatusMsg, data: statusData{uint32(protocol), 999, dMoment, number, head.Hash(), genesis.Hash()}, + code: StatusMsg, data: statusData{uint32(protocol), 999, number, head.Hash(), genesis.Hash()}, wantError: errResp(ErrNetworkIdMismatch, "999 (!= 237)"), }, { - 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}}, + code: StatusMsg, data: statusData{uint32(protocol), DefaultConfig.NetworkId, number, head.Hash(), common.Hash{3}}, wantError: errResp(ErrGenesisBlockMismatch, "0300000000000000 (!= %x)", genesis.Hash().Bytes()[:8]), }, } |