|
|
@ -41,9 +41,6 @@ type IndexerConfig struct { |
|
|
|
// The block frequency for creating CHTs.
|
|
|
|
// The block frequency for creating CHTs.
|
|
|
|
ChtSize uint64 |
|
|
|
ChtSize uint64 |
|
|
|
|
|
|
|
|
|
|
|
// A special auxiliary field represents client's chtsize for server config, otherwise represents server's chtsize.
|
|
|
|
|
|
|
|
PairChtSize uint64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The number of confirmations needed to generate/accept a canonical hash help trie.
|
|
|
|
// The number of confirmations needed to generate/accept a canonical hash help trie.
|
|
|
|
ChtConfirms uint64 |
|
|
|
ChtConfirms uint64 |
|
|
|
|
|
|
|
|
|
|
@ -64,8 +61,7 @@ type IndexerConfig struct { |
|
|
|
var ( |
|
|
|
var ( |
|
|
|
// DefaultServerIndexerConfig wraps a set of configs as a default indexer config for server side.
|
|
|
|
// DefaultServerIndexerConfig wraps a set of configs as a default indexer config for server side.
|
|
|
|
DefaultServerIndexerConfig = &IndexerConfig{ |
|
|
|
DefaultServerIndexerConfig = &IndexerConfig{ |
|
|
|
ChtSize: params.CHTFrequencyServer, |
|
|
|
ChtSize: params.CHTFrequency, |
|
|
|
PairChtSize: params.CHTFrequencyClient, |
|
|
|
|
|
|
|
ChtConfirms: params.HelperTrieProcessConfirmations, |
|
|
|
ChtConfirms: params.HelperTrieProcessConfirmations, |
|
|
|
BloomSize: params.BloomBitsBlocks, |
|
|
|
BloomSize: params.BloomBitsBlocks, |
|
|
|
BloomConfirms: params.BloomConfirms, |
|
|
|
BloomConfirms: params.BloomConfirms, |
|
|
@ -74,8 +70,7 @@ var ( |
|
|
|
} |
|
|
|
} |
|
|
|
// DefaultClientIndexerConfig wraps a set of configs as a default indexer config for client side.
|
|
|
|
// DefaultClientIndexerConfig wraps a set of configs as a default indexer config for client side.
|
|
|
|
DefaultClientIndexerConfig = &IndexerConfig{ |
|
|
|
DefaultClientIndexerConfig = &IndexerConfig{ |
|
|
|
ChtSize: params.CHTFrequencyClient, |
|
|
|
ChtSize: params.CHTFrequency, |
|
|
|
PairChtSize: params.CHTFrequencyServer, |
|
|
|
|
|
|
|
ChtConfirms: params.HelperTrieConfirmations, |
|
|
|
ChtConfirms: params.HelperTrieConfirmations, |
|
|
|
BloomSize: params.BloomBitsBlocksClient, |
|
|
|
BloomSize: params.BloomBitsBlocksClient, |
|
|
|
BloomConfirms: params.HelperTrieConfirmations, |
|
|
|
BloomConfirms: params.HelperTrieConfirmations, |
|
|
@ -84,8 +79,7 @@ var ( |
|
|
|
} |
|
|
|
} |
|
|
|
// TestServerIndexerConfig wraps a set of configs as a test indexer config for server side.
|
|
|
|
// TestServerIndexerConfig wraps a set of configs as a test indexer config for server side.
|
|
|
|
TestServerIndexerConfig = &IndexerConfig{ |
|
|
|
TestServerIndexerConfig = &IndexerConfig{ |
|
|
|
ChtSize: 64, |
|
|
|
ChtSize: 512, |
|
|
|
PairChtSize: 512, |
|
|
|
|
|
|
|
ChtConfirms: 4, |
|
|
|
ChtConfirms: 4, |
|
|
|
BloomSize: 64, |
|
|
|
BloomSize: 64, |
|
|
|
BloomConfirms: 4, |
|
|
|
BloomConfirms: 4, |
|
|
@ -95,7 +89,6 @@ var ( |
|
|
|
// TestClientIndexerConfig wraps a set of configs as a test indexer config for client side.
|
|
|
|
// TestClientIndexerConfig wraps a set of configs as a test indexer config for client side.
|
|
|
|
TestClientIndexerConfig = &IndexerConfig{ |
|
|
|
TestClientIndexerConfig = &IndexerConfig{ |
|
|
|
ChtSize: 512, |
|
|
|
ChtSize: 512, |
|
|
|
PairChtSize: 64, |
|
|
|
|
|
|
|
ChtConfirms: 32, |
|
|
|
ChtConfirms: 32, |
|
|
|
BloomSize: 512, |
|
|
|
BloomSize: 512, |
|
|
|
BloomConfirms: 32, |
|
|
|
BloomConfirms: 32, |
|
|
@ -116,7 +109,7 @@ var ( |
|
|
|
ErrNoTrustedCht = errors.New("no trusted canonical hash trie") |
|
|
|
ErrNoTrustedCht = errors.New("no trusted canonical hash trie") |
|
|
|
ErrNoTrustedBloomTrie = errors.New("no trusted bloom trie") |
|
|
|
ErrNoTrustedBloomTrie = errors.New("no trusted bloom trie") |
|
|
|
ErrNoHeader = errors.New("header not found") |
|
|
|
ErrNoHeader = errors.New("header not found") |
|
|
|
chtPrefix = []byte("chtRoot-") // chtPrefix + chtNum (uint64 big endian) -> trie root hash
|
|
|
|
chtPrefix = []byte("chtRootV2-") // chtPrefix + chtNum (uint64 big endian) -> trie root hash
|
|
|
|
ChtTablePrefix = "cht-" |
|
|
|
ChtTablePrefix = "cht-" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
@ -127,7 +120,6 @@ type ChtNode struct { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetChtRoot reads the CHT root associated to the given section from the database
|
|
|
|
// GetChtRoot reads the CHT root associated to the given section from the database
|
|
|
|
// Note that sectionIdx is specified according to LES/1 CHT section size.
|
|
|
|
|
|
|
|
func GetChtRoot(db ethdb.Database, sectionIdx uint64, sectionHead common.Hash) common.Hash { |
|
|
|
func GetChtRoot(db ethdb.Database, sectionIdx uint64, sectionHead common.Hash) common.Hash { |
|
|
|
var encNumber [8]byte |
|
|
|
var encNumber [8]byte |
|
|
|
binary.BigEndian.PutUint64(encNumber[:], sectionIdx) |
|
|
|
binary.BigEndian.PutUint64(encNumber[:], sectionIdx) |
|
|
@ -136,7 +128,6 @@ func GetChtRoot(db ethdb.Database, sectionIdx uint64, sectionHead common.Hash) c |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// StoreChtRoot writes the CHT root associated to the given section into the database
|
|
|
|
// StoreChtRoot writes the CHT root associated to the given section into the database
|
|
|
|
// Note that sectionIdx is specified according to LES/1 CHT section size.
|
|
|
|
|
|
|
|
func StoreChtRoot(db ethdb.Database, sectionIdx uint64, sectionHead, root common.Hash) { |
|
|
|
func StoreChtRoot(db ethdb.Database, sectionIdx uint64, sectionHead, root common.Hash) { |
|
|
|
var encNumber [8]byte |
|
|
|
var encNumber [8]byte |
|
|
|
binary.BigEndian.PutUint64(encNumber[:], sectionIdx) |
|
|
|
binary.BigEndian.PutUint64(encNumber[:], sectionIdx) |
|
|
@ -163,7 +154,7 @@ func NewChtIndexer(db ethdb.Database, odr OdrBackend, size, confirms uint64) *co |
|
|
|
triedb: trie.NewDatabaseWithCache(trieTable, 1), // Use a tiny cache only to keep memory down
|
|
|
|
triedb: trie.NewDatabaseWithCache(trieTable, 1), // Use a tiny cache only to keep memory down
|
|
|
|
sectionSize: size, |
|
|
|
sectionSize: size, |
|
|
|
} |
|
|
|
} |
|
|
|
return core.NewChainIndexer(db, rawdb.NewTable(db, "chtIndex-"), backend, size, confirms, time.Millisecond*100, "cht") |
|
|
|
return core.NewChainIndexer(db, rawdb.NewTable(db, "chtIndexV2-"), backend, size, confirms, time.Millisecond*100, "cht") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// fetchMissingNodes tries to retrieve the last entry of the latest trusted CHT from the
|
|
|
|
// fetchMissingNodes tries to retrieve the last entry of the latest trusted CHT from the
|
|
|
@ -235,9 +226,7 @@ func (c *ChtIndexerBackend) Commit() error { |
|
|
|
} |
|
|
|
} |
|
|
|
c.triedb.Commit(root, false) |
|
|
|
c.triedb.Commit(root, false) |
|
|
|
|
|
|
|
|
|
|
|
if ((c.section+1)*c.sectionSize)%params.CHTFrequencyClient == 0 { |
|
|
|
log.Info("Storing CHT", "section", c.section, "head", fmt.Sprintf("%064x", c.lastHash), "root", fmt.Sprintf("%064x", root)) |
|
|
|
log.Info("Storing CHT", "section", c.section*c.sectionSize/params.CHTFrequencyClient, "head", fmt.Sprintf("%064x", c.lastHash), "root", fmt.Sprintf("%064x", root)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
StoreChtRoot(c.diskdb, c.section, c.lastHash, root) |
|
|
|
StoreChtRoot(c.diskdb, c.section, c.lastHash, root) |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|