aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2016-11-09 08:20:49 +0800
committerFelix Lange <fjl@twurst.com>2016-11-09 09:19:07 +0800
commitbe3865211c2d8f71e0733b17c469881502e89371 (patch)
tree1b92be622d4d54d7f7d2ecfb9652c9a071172cd6
parent0f19cbc6e5b842fb271eedeed47f433d0c63ff2e (diff)
downloaddexon-be3865211c2d8f71e0733b17c469881502e89371.tar.gz
dexon-be3865211c2d8f71e0733b17c469881502e89371.tar.zst
dexon-be3865211c2d8f71e0733b17c469881502e89371.zip
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.
-rw-r--r--core/database_util.go12
-rw-r--r--core/types/block.go9
-rw-r--r--eth/filters/filter_system.go4
-rw-r--r--eth/gasprice/lightprice.go2
-rw-r--r--les/fetcher.go4
-rw-r--r--les/odr_test.go2
-rw-r--r--les/request_test.go4
-rw-r--r--les/server.go4
-rw-r--r--light/lightchain_test.go2
-rw-r--r--light/odr_test.go2
-rw-r--r--light/txpool.go14
-rw-r--r--light/vm_env.go2
12 files changed, 26 insertions, 35 deletions
diff --git a/core/database_util.go b/core/database_util.go
index 73fac20aa..0fb593554 100644
--- a/core/database_util.go
+++ b/core/database_util.go
@@ -632,24 +632,24 @@ func GetChainConfig(db ethdb.Database, hash common.Hash) (*ChainConfig, error) {
// FindCommonAncestor returns the last common ancestor of two block headers
func FindCommonAncestor(db ethdb.Database, a, b *types.Header) *types.Header {
- for a.GetNumberU64() > b.GetNumberU64() {
- a = GetHeader(db, a.ParentHash, a.GetNumberU64()-1)
+ for bn := b.Number.Uint64(); a.Number.Uint64() > bn; {
+ a = GetHeader(db, a.ParentHash, a.Number.Uint64()-1)
if a == nil {
return nil
}
}
- for a.GetNumberU64() < b.GetNumberU64() {
- b = GetHeader(db, b.ParentHash, b.GetNumberU64()-1)
+ for an := a.Number.Uint64(); an < b.Number.Uint64(); {
+ b = GetHeader(db, b.ParentHash, b.Number.Uint64()-1)
if b == nil {
return nil
}
}
for a.Hash() != b.Hash() {
- a = GetHeader(db, a.ParentHash, a.GetNumberU64()-1)
+ a = GetHeader(db, a.ParentHash, a.Number.Uint64()-1)
if a == nil {
return nil
}
- b = GetHeader(db, b.ParentHash, b.GetNumberU64()-1)
+ b = GetHeader(db, b.ParentHash, b.Number.Uint64()-1)
if b == nil {
return nil
}
diff --git a/core/types/block.go b/core/types/block.go
index 4accb0ee3..fedcfdbbe 100644
--- a/core/types/block.go
+++ b/core/types/block.go
@@ -116,15 +116,6 @@ type jsonHeader struct {
Nonce *BlockNonce `json:"nonce"`
}
-func (h *Header) GetNumber() *big.Int { return new(big.Int).Set(h.Number) }
-func (h *Header) GetGasLimit() *big.Int { return new(big.Int).Set(h.GasLimit) }
-func (h *Header) GetGasUsed() *big.Int { return new(big.Int).Set(h.GasUsed) }
-func (h *Header) GetDifficulty() *big.Int { return new(big.Int).Set(h.Difficulty) }
-func (h *Header) GetTime() *big.Int { return new(big.Int).Set(h.Time) }
-func (h *Header) GetNumberU64() uint64 { return h.Number.Uint64() }
-func (h *Header) GetNonce() uint64 { return binary.BigEndian.Uint64(h.Nonce[:]) }
-func (h *Header) GetExtra() []byte { return common.CopyBytes(h.Extra) }
-
// Hash returns the block hash of the header, which is simply the keccak256 hash of its
// RLP encoding.
func (h *Header) Hash() common.Hash {
diff --git a/eth/filters/filter_system.go b/eth/filters/filter_system.go
index 1e330b24f..c2c072a9f 100644
--- a/eth/filters/filter_system.go
+++ b/eth/filters/filter_system.go
@@ -309,11 +309,11 @@ func (es *EventSystem) lightFilterNewHead(newHeader *types.Header, callBack func
// find common ancestor, create list of rolled back and new block hashes
var oldHeaders, newHeaders []*types.Header
for oldh.Hash() != newh.Hash() {
- if oldh.GetNumberU64() >= newh.GetNumberU64() {
+ if oldh.Number.Uint64() >= newh.Number.Uint64() {
oldHeaders = append(oldHeaders, oldh)
oldh = core.GetHeader(es.backend.ChainDb(), oldh.ParentHash, oldh.Number.Uint64()-1)
}
- if oldh.GetNumberU64() < newh.GetNumberU64() {
+ if oldh.Number.Uint64() < newh.Number.Uint64() {
newHeaders = append(newHeaders, newh)
newh = core.GetHeader(es.backend.ChainDb(), newh.ParentHash, newh.Number.Uint64()-1)
if newh == nil {
diff --git a/eth/gasprice/lightprice.go b/eth/gasprice/lightprice.go
index ce075ff4e..f6d290bb7 100644
--- a/eth/gasprice/lightprice.go
+++ b/eth/gasprice/lightprice.go
@@ -78,7 +78,7 @@ func (self *LightPriceOracle) SuggestPrice(ctx context.Context) (*big.Int, error
return lastPrice, nil
}
- blockNum := head.GetNumberU64()
+ blockNum := head.Number.Uint64()
chn := make(chan lpResult, LpoMaxBlocks)
sent := 0
exp := 0
diff --git a/les/fetcher.go b/les/fetcher.go
index 3fa5cf0e2..d93b7db37 100644
--- a/les/fetcher.go
+++ b/les/fetcher.go
@@ -103,7 +103,7 @@ func (f *lightFetcher) gotHeader(header *types.Header) {
if peerList == nil {
return
}
- number := header.GetNumberU64()
+ number := header.Number.Uint64()
td := core.GetTd(f.pm.chainDb, hash, number)
for _, peer := range peerList {
peer.lock.Lock()
@@ -201,7 +201,7 @@ func (f *lightFetcher) processResponse(req fetchRequest, resp fetchResponse) boo
return false
}
for _, header := range headers {
- td := core.GetTd(f.pm.chainDb, header.Hash(), header.GetNumberU64())
+ td := core.GetTd(f.pm.chainDb, header.Hash(), header.Number.Uint64())
if td == nil {
return false
}
diff --git a/les/odr_test.go b/les/odr_test.go
index bd52a82dd..cdf62464b 100644
--- a/les/odr_test.go
+++ b/les/odr_test.go
@@ -193,7 +193,7 @@ func testOdr(t *testing.T, protocol int, expFail uint64, fn odrTestFn) {
lpm.synchronise(lpeer)
test := func(expFail uint64) {
- for i := uint64(0); i <= pm.blockchain.CurrentHeader().GetNumberU64(); i++ {
+ for i := uint64(0); i <= pm.blockchain.CurrentHeader().Number.Uint64(); i++ {
bhash := core.GetCanonicalHash(db, i)
b1 := fn(light.NoOdr, db, pm.chainConfig, pm.blockchain.(*core.BlockChain), nil, bhash)
ctx, _ := context.WithTimeout(context.Background(), 200*time.Millisecond)
diff --git a/les/request_test.go b/les/request_test.go
index df02afb32..77788d4a9 100644
--- a/les/request_test.go
+++ b/les/request_test.go
@@ -42,7 +42,7 @@ func TestCodeAccessLes1(t *testing.T) { testAccess(t, 1, tfCodeAccess) }
func tfCodeAccess(db ethdb.Database, bhash common.Hash, number uint64) light.OdrRequest {
header := core.GetHeader(db, bhash, core.GetBlockNumber(db, bhash))
- if header.GetNumberU64() < testContractDeployed {
+ if header.Number.Uint64() < testContractDeployed {
return nil
}
sti := light.StateTrieID(header)
@@ -66,7 +66,7 @@ func testAccess(t *testing.T, protocol int, fn accessTestFn) {
lpm.synchronise(lpeer)
test := func(expFail uint64) {
- for i := uint64(0); i <= pm.blockchain.CurrentHeader().GetNumberU64(); i++ {
+ for i := uint64(0); i <= pm.blockchain.CurrentHeader().Number.Uint64(); i++ {
bhash := core.GetCanonicalHash(db, i)
if req := fn(ldb, bhash, i); req != nil {
ctx, _ := context.WithTimeout(context.Background(), 200*time.Millisecond)
diff --git a/les/server.go b/les/server.go
index 874586a7e..0f0e2db42 100644
--- a/les/server.go
+++ b/les/server.go
@@ -279,12 +279,12 @@ func (pm *ProtocolManager) blockLoop() {
if len(peers) > 0 {
header := ev.Data.(core.ChainHeadEvent).Block.Header()
hash := header.Hash()
- number := header.GetNumberU64()
+ number := header.Number.Uint64()
td := core.GetTd(pm.chainDb, hash, number)
if td != nil && td.Cmp(lastBroadcastTd) > 0 {
var reorg uint64
if lastHead != nil {
- reorg = lastHead.GetNumberU64() - core.FindCommonAncestor(pm.chainDb, header, lastHead).GetNumberU64()
+ reorg = lastHead.Number.Uint64() - core.FindCommonAncestor(pm.chainDb, header, lastHead).Number.Uint64()
}
lastHead = header
lastBroadcastTd = td
diff --git a/light/lightchain_test.go b/light/lightchain_test.go
index b7668a3b5..60b909e97 100644
--- a/light/lightchain_test.go
+++ b/light/lightchain_test.go
@@ -134,7 +134,7 @@ func testFork(t *testing.T, LightChain *LightChain, i, n int, comparator func(td
}
func printChain(bc *LightChain) {
- for i := bc.CurrentHeader().GetNumberU64(); i > 0; i-- {
+ for i := bc.CurrentHeader().Number.Uint64(); i > 0; i-- {
b := bc.GetHeaderByNumber(uint64(i))
fmt.Printf("\t%x %v\n", b.Hash(), b.Difficulty)
}
diff --git a/light/odr_test.go b/light/odr_test.go
index 1cf9bce3c..892b56e94 100644
--- a/light/odr_test.go
+++ b/light/odr_test.go
@@ -295,7 +295,7 @@ func testChainOdr(t *testing.T, protocol int, expFail uint64, fn odrTestFn) {
}
test := func(expFail uint64) {
- for i := uint64(0); i <= blockchain.CurrentHeader().GetNumberU64(); i++ {
+ for i := uint64(0); i <= blockchain.CurrentHeader().Number.Uint64(); i++ {
bhash := core.GetCanonicalHash(sdb, i)
b1 := fn(NoOdr, sdb, blockchain, nil, bhash)
ctx, _ := context.WithTimeout(context.Background(), 200*time.Millisecond)
diff --git a/light/txpool.go b/light/txpool.go
index 01fd54597..5c4e2dd82 100644
--- a/light/txpool.go
+++ b/light/txpool.go
@@ -90,7 +90,7 @@ func NewTxPool(config *core.ChainConfig, eventMux *event.TypeMux, chain *LightCh
odr: chain.Odr(),
chainDb: chain.Odr().Database(),
head: chain.CurrentHeader().Hash(),
- clearIdx: chain.CurrentHeader().GetNumberU64(),
+ clearIdx: chain.CurrentHeader().Number.Uint64(),
}
go pool.eventLoop()
@@ -241,11 +241,11 @@ func (pool *TxPool) setNewHead(ctx context.Context, newHeader *types.Header) (tx
// find common ancestor, create list of rolled back and new block hashes
var oldHashes, newHashes []common.Hash
for oldh.Hash() != newh.Hash() {
- if oldh.GetNumberU64() >= newh.GetNumberU64() {
+ if oldh.Number.Uint64() >= newh.Number.Uint64() {
oldHashes = append(oldHashes, oldh.Hash())
oldh = pool.chain.GetHeader(oldh.ParentHash, oldh.Number.Uint64()-1)
}
- if oldh.GetNumberU64() < newh.GetNumberU64() {
+ if oldh.Number.Uint64() < newh.Number.Uint64() {
newHashes = append(newHashes, newh.Hash())
newh = pool.chain.GetHeader(newh.ParentHash, newh.Number.Uint64()-1)
if newh == nil {
@@ -254,8 +254,8 @@ func (pool *TxPool) setNewHead(ctx context.Context, newHeader *types.Header) (tx
}
}
}
- if oldh.GetNumberU64() < pool.clearIdx {
- pool.clearIdx = oldh.GetNumberU64()
+ if oldh.Number.Uint64() < pool.clearIdx {
+ pool.clearIdx = oldh.Number.Uint64()
}
// roll back old blocks
for _, hash := range oldHashes {
@@ -265,14 +265,14 @@ func (pool *TxPool) setNewHead(ctx context.Context, newHeader *types.Header) (tx
// check mined txs of new blocks (array is in reversed order)
for i := len(newHashes) - 1; i >= 0; i-- {
hash := newHashes[i]
- if err := pool.checkMinedTxs(ctx, hash, newHeader.GetNumberU64()-uint64(i), txc); err != nil {
+ if err := pool.checkMinedTxs(ctx, hash, newHeader.Number.Uint64()-uint64(i), txc); err != nil {
return txc, err
}
pool.head = hash
}
// clear old mined tx entries of old blocks
- if idx := newHeader.GetNumberU64(); idx > pool.clearIdx+txPermanent {
+ if idx := newHeader.Number.Uint64(); idx > pool.clearIdx+txPermanent {
idx2 := idx - txPermanent
for i := pool.clearIdx; i < idx2; i++ {
hash := core.GetCanonicalHash(pool.chainDb, i)
diff --git a/light/vm_env.go b/light/vm_env.go
index 0f4b90908..e2b43b99b 100644
--- a/light/vm_env.go
+++ b/light/vm_env.go
@@ -71,7 +71,7 @@ func (self *VMEnv) Depth() int { return self.depth }
func (self *VMEnv) SetDepth(i int) { self.depth = i }
func (self *VMEnv) GetHash(n uint64) common.Hash {
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) {
- if header.GetNumberU64() == n {
+ if header.Number.Uint64() == n {
return header.Hash()
}
}