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

Lines changed: 26 additions & 35 deletions

File tree

‎core/database_util.go‎

Lines changed: 6 additions & 6 deletions
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‎

Lines changed: 0 additions & 9 deletions
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‎

Lines changed: 2 additions & 2 deletions
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‎

Lines changed: 1 addition & 1 deletion
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‎

Lines changed: 2 additions & 2 deletions
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‎

Lines changed: 1 addition & 1 deletion
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‎

Lines changed: 2 additions & 2 deletions
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‎

Lines changed: 2 additions & 2 deletions
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‎

Lines changed: 1 addition & 1 deletion
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‎

Lines changed: 1 addition & 1 deletion
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)

0 commit comments

Comments
 (0)