aboutsummaryrefslogtreecommitdiffstats
path: root/les/odr.go
diff options
context:
space:
mode:
authorFelföldi Zsolt <zsfelfoldi@gmail.com>2017-10-24 21:19:09 +0800
committerFelix Lange <fjl@users.noreply.github.com>2017-10-24 21:19:09 +0800
commitca376ead88a5a26626a90abdb62f4de7f6313822 (patch)
tree71d11e3b6cd40d2bf29033b7e23d30d04e086558 /les/odr.go
parent6d6a5a93370371a33fb815d7ae47b60c7021c86a (diff)
downloaddexon-ca376ead88a5a26626a90abdb62f4de7f6313822.tar.gz
dexon-ca376ead88a5a26626a90abdb62f4de7f6313822.tar.zst
dexon-ca376ead88a5a26626a90abdb62f4de7f6313822.zip
les, light: LES/2 protocol version (#14970)
This PR implements the new LES protocol version extensions: * new and more efficient Merkle proofs reply format (when replying to a multiple Merkle proofs request, we just send a single set of trie nodes containing all necessary nodes) * BBT (BloomBitsTrie) works similarly to the existing CHT and contains the bloombits search data to speed up log searches * GetTxStatusMsg returns the inclusion position or the pending/queued/unknown state of a transaction referenced by hash * an optional signature of new block data (number/hash/td) can be included in AnnounceMsg to provide an option for "very light clients" (mobile/embedded devices) to skip expensive Ethash check and accept multiple signatures of somewhat trusted servers (still a lot better than trusting a single server completely and retrieving everything through RPC). The new client mode is not implemented in this PR, just the protocol extension.
Diffstat (limited to 'les/odr.go')
-rw-r--r--les/odr.go46
1 files changed, 35 insertions, 11 deletions
diff --git a/les/odr.go b/les/odr.go
index 3f7584b48..986630dbf 100644
--- a/les/odr.go
+++ b/les/odr.go
@@ -19,6 +19,7 @@ package les
import (
"context"
+ "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/light"
"github.com/ethereum/go-ethereum/log"
@@ -26,33 +27,56 @@ import (
// LesOdr implements light.OdrBackend
type LesOdr struct {
- db ethdb.Database
- stop chan struct{}
- retriever *retrieveManager
+ db ethdb.Database
+ chtIndexer, bloomTrieIndexer, bloomIndexer *core.ChainIndexer
+ retriever *retrieveManager
+ stop chan struct{}
}
-func NewLesOdr(db ethdb.Database, retriever *retrieveManager) *LesOdr {
+func NewLesOdr(db ethdb.Database, chtIndexer, bloomTrieIndexer, bloomIndexer *core.ChainIndexer, retriever *retrieveManager) *LesOdr {
return &LesOdr{
- db: db,
- retriever: retriever,
- stop: make(chan struct{}),
+ db: db,
+ chtIndexer: chtIndexer,
+ bloomTrieIndexer: bloomTrieIndexer,
+ bloomIndexer: bloomIndexer,
+ retriever: retriever,
+ stop: make(chan struct{}),
}
}
+// Stop cancels all pending retrievals
func (odr *LesOdr) Stop() {
close(odr.stop)
}
+// Database returns the backing database
func (odr *LesOdr) Database() ethdb.Database {
return odr.db
}
+// ChtIndexer returns the CHT chain indexer
+func (odr *LesOdr) ChtIndexer() *core.ChainIndexer {
+ return odr.chtIndexer
+}
+
+// BloomTrieIndexer returns the bloom trie chain indexer
+func (odr *LesOdr) BloomTrieIndexer() *core.ChainIndexer {
+ return odr.bloomTrieIndexer
+}
+
+// BloomIndexer returns the bloombits chain indexer
+func (odr *LesOdr) BloomIndexer() *core.ChainIndexer {
+ return odr.bloomIndexer
+}
+
const (
MsgBlockBodies = iota
MsgCode
MsgReceipts
- MsgProofs
+ MsgProofsV1
+ MsgProofsV2
MsgHeaderProofs
+ MsgHelperTrieProofs
)
// Msg encodes a LES message that delivers reply data for a request
@@ -64,7 +88,7 @@ type Msg struct {
// Retrieve tries to fetch an object from the LES network.
// If the network retrieval was successful, it stores the object in local db.
-func (self *LesOdr) Retrieve(ctx context.Context, req light.OdrRequest) (err error) {
+func (odr *LesOdr) Retrieve(ctx context.Context, req light.OdrRequest) (err error) {
lreq := LesRequest(req)
reqID := genReqID()
@@ -84,9 +108,9 @@ func (self *LesOdr) Retrieve(ctx context.Context, req light.OdrRequest) (err err
},
}
- if err = self.retriever.retrieve(ctx, reqID, rq, func(p distPeer, msg *Msg) error { return lreq.Validate(self.db, msg) }); err == nil {
+ if err = odr.retriever.retrieve(ctx, reqID, rq, func(p distPeer, msg *Msg) error { return lreq.Validate(odr.db, msg) }, odr.stop); err == nil {
// retrieved from network, store in db
- req.StoreResult(self.db)
+ req.StoreResult(odr.db)
} else {
log.Debug("Failed to retrieve data from network", "err", err)
}