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.
pull/3232/head
Felix Lange 8 years ago
parent 0f19cbc6e5
commit be3865211c
  1. 12
      core/database_util.go
  2. 9
      core/types/block.go
  3. 4
      eth/filters/filter_system.go
  4. 2
      eth/gasprice/lightprice.go
  5. 4
      les/fetcher.go
  6. 2
      les/odr_test.go
  7. 4
      les/request_test.go
  8. 4
      les/server.go
  9. 2
      light/lightchain_test.go
  10. 2
      light/odr_test.go
  11. 14
      light/txpool.go
  12. 2
      light/vm_env.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
}

@ -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 {

@ -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 {

@ -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

@ -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
}

@ -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)

@ -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)

@ -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

@ -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)
}

@ -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)

@ -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)

@ -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()
}
}

Loading…
Cancel
Save