mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
internal/era,cmd: add number method to era iterator to get the current block number
This commit is contained in:
parent
02b3f1983e
commit
b98b6d6524
3 changed files with 20 additions and 12 deletions
|
|
@ -248,7 +248,6 @@ func verify(ctx *cli.Context) error {
|
||||||
func checkAccumulator(e *era.Era) error {
|
func checkAccumulator(e *era.Era) error {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
start = e.Start()
|
|
||||||
want common.Hash
|
want common.Hash
|
||||||
td *big.Int
|
td *big.Int
|
||||||
tds = make([]*big.Int, 0)
|
tds = make([]*big.Int, 0)
|
||||||
|
|
@ -271,15 +270,15 @@ func checkAccumulator(e *era.Era) error {
|
||||||
// * the accumulator is correct by recomputing it locally,
|
// * the accumulator is correct by recomputing it locally,
|
||||||
// which verifies the blocks are all correct (via hash)
|
// which verifies the blocks are all correct (via hash)
|
||||||
// * the receipts root matches the value in the block
|
// * the receipts root matches the value in the block
|
||||||
for j := 0; it.Next(); j++ {
|
for it.Next() {
|
||||||
// next() walks the block index, so we're able to
|
// next() walks the block index, so we're able to
|
||||||
// implicitly verify it.
|
// implicitly verify it.
|
||||||
if it.Error() != nil {
|
if it.Error() != nil {
|
||||||
return fmt.Errorf("error reading block %d: %w", start+uint64(j), err)
|
return fmt.Errorf("error reading block %d: %w", it.Number(), err)
|
||||||
}
|
}
|
||||||
block, receipts, err := it.BlockAndReceipts()
|
block, receipts, err := it.BlockAndReceipts()
|
||||||
if it.Error() != nil {
|
if it.Error() != nil {
|
||||||
return fmt.Errorf("error reading block %d: %w", start+uint64(j), err)
|
return fmt.Errorf("error reading block %d: %w", it.Number(), err)
|
||||||
}
|
}
|
||||||
tr := types.DeriveSha(block.Transactions(), trie.NewStackTrie(nil))
|
tr := types.DeriveSha(block.Transactions(), trie.NewStackTrie(nil))
|
||||||
if tr != block.TxHash() {
|
if tr != block.TxHash() {
|
||||||
|
|
|
||||||
|
|
@ -293,32 +293,31 @@ func ImportHistory(chain *core.BlockChain, db ethdb.Database, dir string, networ
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error making era reader: %w", err)
|
return fmt.Errorf("error making era reader: %w", err)
|
||||||
}
|
}
|
||||||
for j := 0; it.Next(); j++ {
|
for it.Next() {
|
||||||
n := i*era.MaxEra1Size + j
|
|
||||||
block, err := it.Block()
|
block, err := it.Block()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error reading block %d: %w", n, err)
|
return fmt.Errorf("error reading block %d: %w", it.Number(), err)
|
||||||
}
|
}
|
||||||
if block.Number().BitLen() == 0 {
|
if block.Number().BitLen() == 0 {
|
||||||
continue // skip genesis
|
continue // skip genesis
|
||||||
}
|
}
|
||||||
receipts, err := it.Receipts()
|
receipts, err := it.Receipts()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error reading receipts %d: %w", n, err)
|
return fmt.Errorf("error reading receipts %d: %w", it.Number(), err)
|
||||||
}
|
}
|
||||||
if status, err := chain.HeaderChain().InsertHeaderChain([]*types.Header{block.Header()}, start, forker); err != nil {
|
if status, err := chain.HeaderChain().InsertHeaderChain([]*types.Header{block.Header()}, start, forker); err != nil {
|
||||||
return fmt.Errorf("error inserting header %d: %w", n, err)
|
return fmt.Errorf("error inserting header %d: %w", it.Number(), err)
|
||||||
} else if status != core.CanonStatTy {
|
} else if status != core.CanonStatTy {
|
||||||
return fmt.Errorf("error inserting header %d, not canon: %v", n, status)
|
return fmt.Errorf("error inserting header %d, not canon: %v", it.Number(), status)
|
||||||
}
|
}
|
||||||
if _, err := chain.InsertReceiptChain([]*types.Block{block}, []types.Receipts{receipts}, 2^64-1); err != nil {
|
if _, err := chain.InsertReceiptChain([]*types.Block{block}, []types.Receipts{receipts}, 2^64-1); err != nil {
|
||||||
return fmt.Errorf("error inserting body %d: %w", n, err)
|
return fmt.Errorf("error inserting body %d: %w", it.Number(), err)
|
||||||
}
|
}
|
||||||
imported += 1
|
imported += 1
|
||||||
|
|
||||||
// Give the user some feedback that something is happening.
|
// Give the user some feedback that something is happening.
|
||||||
if time.Since(reported) >= 8*time.Second {
|
if time.Since(reported) >= 8*time.Second {
|
||||||
log.Info("Importing Era files", "head", n, "imported", imported, "elapsed", common.PrettyDuration(time.Since(start)))
|
log.Info("Importing Era files", "head", it.Number(), "imported", imported, "elapsed", common.PrettyDuration(time.Since(start)))
|
||||||
imported = 0
|
imported = 0
|
||||||
reported = time.Now()
|
reported = time.Now()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,11 @@ func (it *Iterator) Next() bool {
|
||||||
return it.inner.Next()
|
return it.inner.Next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Number returns the current number block the iterator will return.
|
||||||
|
func (it *Iterator) Number() uint64 {
|
||||||
|
return it.inner.next - 1
|
||||||
|
}
|
||||||
|
|
||||||
// Error returns the error status of the iterator.
|
// Error returns the error status of the iterator.
|
||||||
func (it *Iterator) Error() error {
|
func (it *Iterator) Error() error {
|
||||||
return it.inner.Error()
|
return it.inner.Error()
|
||||||
|
|
@ -145,6 +150,11 @@ func (it *RawIterator) Next() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Number returns the current number block the iterator will return.
|
||||||
|
func (it *RawIterator) Number() uint64 {
|
||||||
|
return it.next - 1
|
||||||
|
}
|
||||||
|
|
||||||
// Error returns the error status of the iterator.
|
// Error returns the error status of the iterator.
|
||||||
func (it *RawIterator) Error() error {
|
func (it *RawIterator) Error() error {
|
||||||
if it.err == io.EOF {
|
if it.err == io.EOF {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue