Prefer Block.NumberU64() over Block.Number.Uint64() (#3051)

This commit is contained in:
TBC Dev 2021-11-29 19:32:41 +08:00 committed by GitHub
parent 0e6e47e913
commit ae4819ddad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 10 additions and 10 deletions

View File

@ -33,10 +33,10 @@ func TestPendingBlock(t *testing.T) {
ff.HandlePendingBlock(&txpool.OnPendingBlockReply{RplBlock: b})
block := api.pendingBlock()
require.Equal(t, block.Number().Uint64(), expect)
require.Equal(t, block.NumberU64(), expect)
select {
case got := <-ch:
require.Equal(t, expect, got.Number().Uint64())
require.Equal(t, expect, got.NumberU64())
case <-time.After(100 * time.Millisecond):
t.Fatalf("timeout waiting for expected notification")
}

View File

@ -145,7 +145,7 @@ func CheckChangeSets(genesis *core.Genesis, logger log.Logger, blockNum uint64,
return err1
}
if writeReceipts {
if chainConfig.IsByzantium(block.Number().Uint64()) {
if chainConfig.IsByzantium(block.NumberU64()) {
receiptSha := types.DeriveSha(receipts)
if receiptSha != block.ReceiptHash() {
return fmt.Errorf("mismatched receipt headers for block %d", block.NumberU64())

View File

@ -555,7 +555,7 @@ func OpcodeTracer(genesis *core.Genesis, blockNum uint64, chaindata string, numB
if err1 != nil {
return err1
}
if chainConfig.IsByzantium(block.Number().Uint64()) {
if chainConfig.IsByzantium(block.NumberU64()) {
receiptSha := types.DeriveSha(receipts)
if receiptSha != block.ReceiptHash() {
return fmt.Errorf("mismatched receipt headers for block %d", block.NumberU64())

View File

@ -302,8 +302,8 @@ func TestStaleSubmission(t *testing.T) {
if res.Difficulty().Uint64() != c.headers[c.submitIndex].Difficulty.Uint64() {
t.Errorf("case %d block difficulty mismatch, want %d, get %d", id+1, c.headers[c.submitIndex].Difficulty, res.Difficulty())
}
if res.Number().Uint64() != c.headers[c.submitIndex].Number.Uint64() {
t.Errorf("case %d block number mismatch, want %d, get %d", id+1, c.headers[c.submitIndex].Number.Uint64(), res.Number().Uint64())
if res.NumberU64() != c.headers[c.submitIndex].Number.Uint64() {
t.Errorf("case %d block number mismatch, want %d, get %d", id+1, c.headers[c.submitIndex].Number.Uint64(), res.NumberU64())
}
if res.ParentHash() != c.headers[c.submitIndex].ParentHash {
t.Errorf("case %d block parent hash mismatch, want %s, get %s", id+1, c.headers[c.submitIndex].ParentHash.Hex(), res.ParentHash().Hex())

View File

@ -376,7 +376,7 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
for i := 0; i < n; i++ {
stateReader := state.NewPlainStateReader(tx)
plainStateWriter := state.NewPlainStateWriter(tx, nil, parent.Number().Uint64()+uint64(i)+1)
plainStateWriter := state.NewPlainStateWriter(tx, nil, parent.NumberU64()+uint64(i)+1)
ibs := state.New(stateReader)
block, receipt, err := genblock(i, parent, ibs, stateReader, plainStateWriter)
if err != nil {
@ -408,7 +408,7 @@ func makeHeader(chain consensus.ChainReader, parent *types.Block, state *state.I
Difficulty: engine.CalcDifficulty(chain, time,
time-10,
parent.Difficulty(),
parent.Number().Uint64(),
parent.NumberU64(),
parent.Hash(),
parent.UncleHash(),
parent.Seal(),

View File

@ -121,7 +121,7 @@ var ReceiptRepair = Migration{
return err1
}
fix := true
if chainConfig.IsByzantium(block.Number().Uint64()) {
if chainConfig.IsByzantium(block.NumberU64()) {
receiptSha := types.DeriveSha(receipts1)
if receiptSha != block.ReceiptHash() {
fmt.Printf("(retrace) mismatched receipt headers for block %d: %x, %x\n", block.NumberU64(), receiptSha, block.ReceiptHash())

View File

@ -186,7 +186,7 @@ func (t *StateTest) RunNoVerify(rules params.Rules, tx kv.RwTx, subtest StateSub
return nil, common.Hash{}, UnsupportedForkError{subtest.Fork}
}
readBlockNr := block.Number().Uint64()
readBlockNr := block.NumberU64()
writeBlockNr := readBlockNr + 1
_, err = MakePreState(params.Rules{}, tx, t.json.Pre, readBlockNr)