Skip to content

Commit be38652

Browse files
committed
core/types: remove header accessors
These accessors were introduced by light client changes, but the only method that is actually used is GetNumberU64. This commit replaces all uses of .GetNumberU64 with .Number.Uint64.
1 parent 0f19cbc commit be38652

12 files changed

+26
-35
lines changed

core/database_util.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -632,24 +632,24 @@ func GetChainConfig(db ethdb.Database, hash common.Hash) (*ChainConfig, error) {
632632

633633
// FindCommonAncestor returns the last common ancestor of two block headers
634634
func FindCommonAncestor(db ethdb.Database, a, b *types.Header) *types.Header {
635-
for a.GetNumberU64() > b.GetNumberU64() {
636-
a = GetHeader(db, a.ParentHash, a.GetNumberU64()-1)
635+
for bn := b.Number.Uint64(); a.Number.Uint64() > bn; {
636+
a = GetHeader(db, a.ParentHash, a.Number.Uint64()-1)
637637
if a == nil {
638638
return nil
639639
}
640640
}
641-
for a.GetNumberU64() < b.GetNumberU64() {
642-
b = GetHeader(db, b.ParentHash, b.GetNumberU64()-1)
641+
for an := a.Number.Uint64(); an < b.Number.Uint64(); {
642+
b = GetHeader(db, b.ParentHash, b.Number.Uint64()-1)
643643
if b == nil {
644644
return nil
645645
}
646646
}
647647
for a.Hash() != b.Hash() {
648-
a = GetHeader(db, a.ParentHash, a.GetNumberU64()-1)
648+
a = GetHeader(db, a.ParentHash, a.Number.Uint64()-1)
649649
if a == nil {
650650
return nil
651651
}
652-
b = GetHeader(db, b.ParentHash, b.GetNumberU64()-1)
652+
b = GetHeader(db, b.ParentHash, b.Number.Uint64()-1)
653653
if b == nil {
654654
return nil
655655
}

core/types/block.go

-9
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,6 @@ type jsonHeader struct {
116116
Nonce *BlockNonce `json:"nonce"`
117117
}
118118

119-
func (h *Header) GetNumber() *big.Int { return new(big.Int).Set(h.Number) }
120-
func (h *Header) GetGasLimit() *big.Int { return new(big.Int).Set(h.GasLimit) }
121-
func (h *Header) GetGasUsed() *big.Int { return new(big.Int).Set(h.GasUsed) }
122-
func (h *Header) GetDifficulty() *big.Int { return new(big.Int).Set(h.Difficulty) }
123-
func (h *Header) GetTime() *big.Int { return new(big.Int).Set(h.Time) }
124-
func (h *Header) GetNumberU64() uint64 { return h.Number.Uint64() }
125-
func (h *Header) GetNonce() uint64 { return binary.BigEndian.Uint64(h.Nonce[:]) }
126-
func (h *Header) GetExtra() []byte { return common.CopyBytes(h.Extra) }
127-
128119
// Hash returns the block hash of the header, which is simply the keccak256 hash of its
129120
// RLP encoding.
130121
func (h *Header) Hash() common.Hash {

eth/filters/filter_system.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,11 @@ func (es *EventSystem) lightFilterNewHead(newHeader *types.Header, callBack func
309309
// find common ancestor, create list of rolled back and new block hashes
310310
var oldHeaders, newHeaders []*types.Header
311311
for oldh.Hash() != newh.Hash() {
312-
if oldh.GetNumberU64() >= newh.GetNumberU64() {
312+
if oldh.Number.Uint64() >= newh.Number.Uint64() {
313313
oldHeaders = append(oldHeaders, oldh)
314314
oldh = core.GetHeader(es.backend.ChainDb(), oldh.ParentHash, oldh.Number.Uint64()-1)
315315
}
316-
if oldh.GetNumberU64() < newh.GetNumberU64() {
316+
if oldh.Number.Uint64() < newh.Number.Uint64() {
317317
newHeaders = append(newHeaders, newh)
318318
newh = core.GetHeader(es.backend.ChainDb(), newh.ParentHash, newh.Number.Uint64()-1)
319319
if newh == nil {

eth/gasprice/lightprice.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (self *LightPriceOracle) SuggestPrice(ctx context.Context) (*big.Int, error
7878
return lastPrice, nil
7979
}
8080

81-
blockNum := head.GetNumberU64()
81+
blockNum := head.Number.Uint64()
8282
chn := make(chan lpResult, LpoMaxBlocks)
8383
sent := 0
8484
exp := 0

les/fetcher.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (f *lightFetcher) gotHeader(header *types.Header) {
103103
if peerList == nil {
104104
return
105105
}
106-
number := header.GetNumberU64()
106+
number := header.Number.Uint64()
107107
td := core.GetTd(f.pm.chainDb, hash, number)
108108
for _, peer := range peerList {
109109
peer.lock.Lock()
@@ -201,7 +201,7 @@ func (f *lightFetcher) processResponse(req fetchRequest, resp fetchResponse) boo
201201
return false
202202
}
203203
for _, header := range headers {
204-
td := core.GetTd(f.pm.chainDb, header.Hash(), header.GetNumberU64())
204+
td := core.GetTd(f.pm.chainDb, header.Hash(), header.Number.Uint64())
205205
if td == nil {
206206
return false
207207
}

les/odr_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func testOdr(t *testing.T, protocol int, expFail uint64, fn odrTestFn) {
193193
lpm.synchronise(lpeer)
194194

195195
test := func(expFail uint64) {
196-
for i := uint64(0); i <= pm.blockchain.CurrentHeader().GetNumberU64(); i++ {
196+
for i := uint64(0); i <= pm.blockchain.CurrentHeader().Number.Uint64(); i++ {
197197
bhash := core.GetCanonicalHash(db, i)
198198
b1 := fn(light.NoOdr, db, pm.chainConfig, pm.blockchain.(*core.BlockChain), nil, bhash)
199199
ctx, _ := context.WithTimeout(context.Background(), 200*time.Millisecond)

les/request_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestCodeAccessLes1(t *testing.T) { testAccess(t, 1, tfCodeAccess) }
4242

4343
func tfCodeAccess(db ethdb.Database, bhash common.Hash, number uint64) light.OdrRequest {
4444
header := core.GetHeader(db, bhash, core.GetBlockNumber(db, bhash))
45-
if header.GetNumberU64() < testContractDeployed {
45+
if header.Number.Uint64() < testContractDeployed {
4646
return nil
4747
}
4848
sti := light.StateTrieID(header)
@@ -66,7 +66,7 @@ func testAccess(t *testing.T, protocol int, fn accessTestFn) {
6666
lpm.synchronise(lpeer)
6767

6868
test := func(expFail uint64) {
69-
for i := uint64(0); i <= pm.blockchain.CurrentHeader().GetNumberU64(); i++ {
69+
for i := uint64(0); i <= pm.blockchain.CurrentHeader().Number.Uint64(); i++ {
7070
bhash := core.GetCanonicalHash(db, i)
7171
if req := fn(ldb, bhash, i); req != nil {
7272
ctx, _ := context.WithTimeout(context.Background(), 200*time.Millisecond)

les/server.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,12 @@ func (pm *ProtocolManager) blockLoop() {
279279
if len(peers) > 0 {
280280
header := ev.Data.(core.ChainHeadEvent).Block.Header()
281281
hash := header.Hash()
282-
number := header.GetNumberU64()
282+
number := header.Number.Uint64()
283283
td := core.GetTd(pm.chainDb, hash, number)
284284
if td != nil && td.Cmp(lastBroadcastTd) > 0 {
285285
var reorg uint64
286286
if lastHead != nil {
287-
reorg = lastHead.GetNumberU64() - core.FindCommonAncestor(pm.chainDb, header, lastHead).GetNumberU64()
287+
reorg = lastHead.Number.Uint64() - core.FindCommonAncestor(pm.chainDb, header, lastHead).Number.Uint64()
288288
}
289289
lastHead = header
290290
lastBroadcastTd = td

light/lightchain_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func testFork(t *testing.T, LightChain *LightChain, i, n int, comparator func(td
134134
}
135135

136136
func printChain(bc *LightChain) {
137-
for i := bc.CurrentHeader().GetNumberU64(); i > 0; i-- {
137+
for i := bc.CurrentHeader().Number.Uint64(); i > 0; i-- {
138138
b := bc.GetHeaderByNumber(uint64(i))
139139
fmt.Printf("\t%x %v\n", b.Hash(), b.Difficulty)
140140
}

light/odr_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func testChainOdr(t *testing.T, protocol int, expFail uint64, fn odrTestFn) {
295295
}
296296

297297
test := func(expFail uint64) {
298-
for i := uint64(0); i <= blockchain.CurrentHeader().GetNumberU64(); i++ {
298+
for i := uint64(0); i <= blockchain.CurrentHeader().Number.Uint64(); i++ {
299299
bhash := core.GetCanonicalHash(sdb, i)
300300
b1 := fn(NoOdr, sdb, blockchain, nil, bhash)
301301
ctx, _ := context.WithTimeout(context.Background(), 200*time.Millisecond)

light/txpool.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func NewTxPool(config *core.ChainConfig, eventMux *event.TypeMux, chain *LightCh
9090
odr: chain.Odr(),
9191
chainDb: chain.Odr().Database(),
9292
head: chain.CurrentHeader().Hash(),
93-
clearIdx: chain.CurrentHeader().GetNumberU64(),
93+
clearIdx: chain.CurrentHeader().Number.Uint64(),
9494
}
9595
go pool.eventLoop()
9696

@@ -241,11 +241,11 @@ func (pool *TxPool) setNewHead(ctx context.Context, newHeader *types.Header) (tx
241241
// find common ancestor, create list of rolled back and new block hashes
242242
var oldHashes, newHashes []common.Hash
243243
for oldh.Hash() != newh.Hash() {
244-
if oldh.GetNumberU64() >= newh.GetNumberU64() {
244+
if oldh.Number.Uint64() >= newh.Number.Uint64() {
245245
oldHashes = append(oldHashes, oldh.Hash())
246246
oldh = pool.chain.GetHeader(oldh.ParentHash, oldh.Number.Uint64()-1)
247247
}
248-
if oldh.GetNumberU64() < newh.GetNumberU64() {
248+
if oldh.Number.Uint64() < newh.Number.Uint64() {
249249
newHashes = append(newHashes, newh.Hash())
250250
newh = pool.chain.GetHeader(newh.ParentHash, newh.Number.Uint64()-1)
251251
if newh == nil {
@@ -254,8 +254,8 @@ func (pool *TxPool) setNewHead(ctx context.Context, newHeader *types.Header) (tx
254254
}
255255
}
256256
}
257-
if oldh.GetNumberU64() < pool.clearIdx {
258-
pool.clearIdx = oldh.GetNumberU64()
257+
if oldh.Number.Uint64() < pool.clearIdx {
258+
pool.clearIdx = oldh.Number.Uint64()
259259
}
260260
// roll back old blocks
261261
for _, hash := range oldHashes {
@@ -265,14 +265,14 @@ func (pool *TxPool) setNewHead(ctx context.Context, newHeader *types.Header) (tx
265265
// check mined txs of new blocks (array is in reversed order)
266266
for i := len(newHashes) - 1; i >= 0; i-- {
267267
hash := newHashes[i]
268-
if err := pool.checkMinedTxs(ctx, hash, newHeader.GetNumberU64()-uint64(i), txc); err != nil {
268+
if err := pool.checkMinedTxs(ctx, hash, newHeader.Number.Uint64()-uint64(i), txc); err != nil {
269269
return txc, err
270270
}
271271
pool.head = hash
272272
}
273273

274274
// clear old mined tx entries of old blocks
275-
if idx := newHeader.GetNumberU64(); idx > pool.clearIdx+txPermanent {
275+
if idx := newHeader.Number.Uint64(); idx > pool.clearIdx+txPermanent {
276276
idx2 := idx - txPermanent
277277
for i := pool.clearIdx; i < idx2; i++ {
278278
hash := core.GetCanonicalHash(pool.chainDb, i)

light/vm_env.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (self *VMEnv) Depth() int { return self.depth }
7171
func (self *VMEnv) SetDepth(i int) { self.depth = i }
7272
func (self *VMEnv) GetHash(n uint64) common.Hash {
7373
for header := self.chain.GetHeader(self.header.ParentHash, self.header.Number.Uint64()-1); header != nil; header = self.chain.GetHeader(header.ParentHash, header.Number.Uint64()-1) {
74-
if header.GetNumberU64() == n {
74+
if header.Number.Uint64() == n {
7575
return header.Hash()
7676
}
7777
}

0 commit comments

Comments
 (0)