diff options
author | Sonic <sonic@dexon.org> | 2018-11-20 14:13:53 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:53 +0800 |
commit | afc01df41cafd3a8b56db9f32e23da3bf0e6b7ef (patch) | |
tree | 28013bb14a19611adecda49d1dfbeb0a34dad66a /dex/downloader/peer.go | |
parent | 2113837c006aad6af75c09d37514591fd6863dbc (diff) | |
download | dexon-afc01df41cafd3a8b56db9f32e23da3bf0e6b7ef.tar dexon-afc01df41cafd3a8b56db9f32e23da3bf0e6b7ef.tar.gz dexon-afc01df41cafd3a8b56db9f32e23da3bf0e6b7ef.tar.bz2 dexon-afc01df41cafd3a8b56db9f32e23da3bf0e6b7ef.tar.lz dexon-afc01df41cafd3a8b56db9f32e23da3bf0e6b7ef.tar.xz dexon-afc01df41cafd3a8b56db9f32e23da3bf0e6b7ef.tar.zst dexon-afc01df41cafd3a8b56db9f32e23da3bf0e6b7ef.zip |
dex: implement downloader for dex
We need governance state to verify block's signature (randomness),
but in ethereum fast sync mode, eth downloader only downloads the whole
state of pivot block, so we don't have governance state to verify the
downloaded block that is before pivot block if we don't processing
transaction.
To avoid running transactions, dex downloader also downloads the
governance state (merkle proof and storage) at snapshot height of each round,
so that we can verify blocks in fast sync mode.
Diffstat (limited to 'dex/downloader/peer.go')
-rw-r--r-- | dex/downloader/peer.go | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/dex/downloader/peer.go b/dex/downloader/peer.go index 1fd82fbe3..b6f2936b7 100644 --- a/dex/downloader/peer.go +++ b/dex/downloader/peer.go @@ -78,8 +78,9 @@ type peerConnection struct { // LightPeer encapsulates the methods required to synchronise with a remote light peer. type LightPeer interface { Head() (common.Hash, *big.Int) - RequestHeadersByHash(common.Hash, int, int, bool) error - RequestHeadersByNumber(uint64, int, int, bool) error + RequestHeadersByHash(common.Hash, int, int, bool, bool) error + RequestHeadersByNumber(uint64, int, int, bool, bool) error + RequestGovStateByHash(common.Hash) error } // Peer encapsulates the methods required to synchronise with a remote full peer. @@ -96,11 +97,15 @@ type lightPeerWrapper struct { } func (w *lightPeerWrapper) Head() (common.Hash, *big.Int) { return w.peer.Head() } -func (w *lightPeerWrapper) RequestHeadersByHash(h common.Hash, amount int, skip int, reverse bool) error { - return w.peer.RequestHeadersByHash(h, amount, skip, reverse) +func (w *lightPeerWrapper) RequestHeadersByHash(h common.Hash, amount int, skip int, reverse, withGov bool) error { + return w.peer.RequestHeadersByHash(h, amount, skip, reverse, withGov) } -func (w *lightPeerWrapper) RequestHeadersByNumber(i uint64, amount int, skip int, reverse bool) error { - return w.peer.RequestHeadersByNumber(i, amount, skip, reverse) +func (w *lightPeerWrapper) RequestHeadersByNumber(i uint64, amount int, skip int, reverse, withGov bool) error { + return w.peer.RequestHeadersByNumber(i, amount, skip, reverse, withGov) +} +func (w *lightPeerWrapper) RequestGovStateByHash(common.Hash) error { + // TODO(sonic): support this + panic("RequestGovStateByHash not supported in light client mode sync") } func (w *lightPeerWrapper) RequestBodies([]common.Hash) error { panic("RequestBodies not supported in light client mode sync") @@ -156,7 +161,7 @@ func (p *peerConnection) FetchHeaders(from uint64, count int) error { p.headerStarted = time.Now() // Issue the header retrieval request (absolut upwards without gaps) - go p.peer.RequestHeadersByNumber(from, count, 0, false) + go p.peer.RequestHeadersByNumber(from, count, 0, false, true) return nil } |