forked from cerc-io/plugeth
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.
This commit is contained in:
parent
0f19cbc6e5
commit
be3865211c
@ -632,24 +632,24 @@ func GetChainConfig(db ethdb.Database, hash common.Hash) (*ChainConfig, error) {
|
|||||||
|
|
||||||
// FindCommonAncestor returns the last common ancestor of two block headers
|
// FindCommonAncestor returns the last common ancestor of two block headers
|
||||||
func FindCommonAncestor(db ethdb.Database, a, b *types.Header) *types.Header {
|
func FindCommonAncestor(db ethdb.Database, a, b *types.Header) *types.Header {
|
||||||
for a.GetNumberU64() > b.GetNumberU64() {
|
for bn := b.Number.Uint64(); a.Number.Uint64() > bn; {
|
||||||
a = GetHeader(db, a.ParentHash, a.GetNumberU64()-1)
|
a = GetHeader(db, a.ParentHash, a.Number.Uint64()-1)
|
||||||
if a == nil {
|
if a == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for a.GetNumberU64() < b.GetNumberU64() {
|
for an := a.Number.Uint64(); an < b.Number.Uint64(); {
|
||||||
b = GetHeader(db, b.ParentHash, b.GetNumberU64()-1)
|
b = GetHeader(db, b.ParentHash, b.Number.Uint64()-1)
|
||||||
if b == nil {
|
if b == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for a.Hash() != b.Hash() {
|
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 {
|
if a == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
b = GetHeader(db, b.ParentHash, b.GetNumberU64()-1)
|
b = GetHeader(db, b.ParentHash, b.Number.Uint64()-1)
|
||||||
if b == nil {
|
if b == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -116,15 +116,6 @@ type jsonHeader struct {
|
|||||||
Nonce *BlockNonce `json:"nonce"`
|
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
|
// Hash returns the block hash of the header, which is simply the keccak256 hash of its
|
||||||
// RLP encoding.
|
// RLP encoding.
|
||||||
func (h *Header) Hash() common.Hash {
|
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
|
// find common ancestor, create list of rolled back and new block hashes
|
||||||
var oldHeaders, newHeaders []*types.Header
|
var oldHeaders, newHeaders []*types.Header
|
||||||
for oldh.Hash() != newh.Hash() {
|
for oldh.Hash() != newh.Hash() {
|
||||||
if oldh.GetNumberU64() >= newh.GetNumberU64() {
|
if oldh.Number.Uint64() >= newh.Number.Uint64() {
|
||||||
oldHeaders = append(oldHeaders, oldh)
|
oldHeaders = append(oldHeaders, oldh)
|
||||||
oldh = core.GetHeader(es.backend.ChainDb(), oldh.ParentHash, oldh.Number.Uint64()-1)
|
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)
|
newHeaders = append(newHeaders, newh)
|
||||||
newh = core.GetHeader(es.backend.ChainDb(), newh.ParentHash, newh.Number.Uint64()-1)
|
newh = core.GetHeader(es.backend.ChainDb(), newh.ParentHash, newh.Number.Uint64()-1)
|
||||||
if newh == nil {
|
if newh == nil {
|
||||||
|
@ -78,7 +78,7 @@ func (self *LightPriceOracle) SuggestPrice(ctx context.Context) (*big.Int, error
|
|||||||
return lastPrice, nil
|
return lastPrice, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
blockNum := head.GetNumberU64()
|
blockNum := head.Number.Uint64()
|
||||||
chn := make(chan lpResult, LpoMaxBlocks)
|
chn := make(chan lpResult, LpoMaxBlocks)
|
||||||
sent := 0
|
sent := 0
|
||||||
exp := 0
|
exp := 0
|
||||||
|
@ -103,7 +103,7 @@ func (f *lightFetcher) gotHeader(header *types.Header) {
|
|||||||
if peerList == nil {
|
if peerList == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
number := header.GetNumberU64()
|
number := header.Number.Uint64()
|
||||||
td := core.GetTd(f.pm.chainDb, hash, number)
|
td := core.GetTd(f.pm.chainDb, hash, number)
|
||||||
for _, peer := range peerList {
|
for _, peer := range peerList {
|
||||||
peer.lock.Lock()
|
peer.lock.Lock()
|
||||||
@ -201,7 +201,7 @@ func (f *lightFetcher) processResponse(req fetchRequest, resp fetchResponse) boo
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for _, header := range headers {
|
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 {
|
if td == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -193,7 +193,7 @@ func testOdr(t *testing.T, protocol int, expFail uint64, fn odrTestFn) {
|
|||||||
lpm.synchronise(lpeer)
|
lpm.synchronise(lpeer)
|
||||||
|
|
||||||
test := func(expFail uint64) {
|
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)
|
bhash := core.GetCanonicalHash(db, i)
|
||||||
b1 := fn(light.NoOdr, db, pm.chainConfig, pm.blockchain.(*core.BlockChain), nil, bhash)
|
b1 := fn(light.NoOdr, db, pm.chainConfig, pm.blockchain.(*core.BlockChain), nil, bhash)
|
||||||
ctx, _ := context.WithTimeout(context.Background(), 200*time.Millisecond)
|
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 {
|
func tfCodeAccess(db ethdb.Database, bhash common.Hash, number uint64) light.OdrRequest {
|
||||||
header := core.GetHeader(db, bhash, core.GetBlockNumber(db, bhash))
|
header := core.GetHeader(db, bhash, core.GetBlockNumber(db, bhash))
|
||||||
if header.GetNumberU64() < testContractDeployed {
|
if header.Number.Uint64() < testContractDeployed {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
sti := light.StateTrieID(header)
|
sti := light.StateTrieID(header)
|
||||||
@ -66,7 +66,7 @@ func testAccess(t *testing.T, protocol int, fn accessTestFn) {
|
|||||||
lpm.synchronise(lpeer)
|
lpm.synchronise(lpeer)
|
||||||
|
|
||||||
test := func(expFail uint64) {
|
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)
|
bhash := core.GetCanonicalHash(db, i)
|
||||||
if req := fn(ldb, bhash, i); req != nil {
|
if req := fn(ldb, bhash, i); req != nil {
|
||||||
ctx, _ := context.WithTimeout(context.Background(), 200*time.Millisecond)
|
ctx, _ := context.WithTimeout(context.Background(), 200*time.Millisecond)
|
||||||
|
@ -279,12 +279,12 @@ func (pm *ProtocolManager) blockLoop() {
|
|||||||
if len(peers) > 0 {
|
if len(peers) > 0 {
|
||||||
header := ev.Data.(core.ChainHeadEvent).Block.Header()
|
header := ev.Data.(core.ChainHeadEvent).Block.Header()
|
||||||
hash := header.Hash()
|
hash := header.Hash()
|
||||||
number := header.GetNumberU64()
|
number := header.Number.Uint64()
|
||||||
td := core.GetTd(pm.chainDb, hash, number)
|
td := core.GetTd(pm.chainDb, hash, number)
|
||||||
if td != nil && td.Cmp(lastBroadcastTd) > 0 {
|
if td != nil && td.Cmp(lastBroadcastTd) > 0 {
|
||||||
var reorg uint64
|
var reorg uint64
|
||||||
if lastHead != nil {
|
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
|
lastHead = header
|
||||||
lastBroadcastTd = td
|
lastBroadcastTd = td
|
||||||
|
@ -134,7 +134,7 @@ func testFork(t *testing.T, LightChain *LightChain, i, n int, comparator func(td
|
|||||||
}
|
}
|
||||||
|
|
||||||
func printChain(bc *LightChain) {
|
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))
|
b := bc.GetHeaderByNumber(uint64(i))
|
||||||
fmt.Printf("\t%x %v\n", b.Hash(), b.Difficulty)
|
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) {
|
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)
|
bhash := core.GetCanonicalHash(sdb, i)
|
||||||
b1 := fn(NoOdr, sdb, blockchain, nil, bhash)
|
b1 := fn(NoOdr, sdb, blockchain, nil, bhash)
|
||||||
ctx, _ := context.WithTimeout(context.Background(), 200*time.Millisecond)
|
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(),
|
odr: chain.Odr(),
|
||||||
chainDb: chain.Odr().Database(),
|
chainDb: chain.Odr().Database(),
|
||||||
head: chain.CurrentHeader().Hash(),
|
head: chain.CurrentHeader().Hash(),
|
||||||
clearIdx: chain.CurrentHeader().GetNumberU64(),
|
clearIdx: chain.CurrentHeader().Number.Uint64(),
|
||||||
}
|
}
|
||||||
go pool.eventLoop()
|
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
|
// find common ancestor, create list of rolled back and new block hashes
|
||||||
var oldHashes, newHashes []common.Hash
|
var oldHashes, newHashes []common.Hash
|
||||||
for oldh.Hash() != newh.Hash() {
|
for oldh.Hash() != newh.Hash() {
|
||||||
if oldh.GetNumberU64() >= newh.GetNumberU64() {
|
if oldh.Number.Uint64() >= newh.Number.Uint64() {
|
||||||
oldHashes = append(oldHashes, oldh.Hash())
|
oldHashes = append(oldHashes, oldh.Hash())
|
||||||
oldh = pool.chain.GetHeader(oldh.ParentHash, oldh.Number.Uint64()-1)
|
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())
|
newHashes = append(newHashes, newh.Hash())
|
||||||
newh = pool.chain.GetHeader(newh.ParentHash, newh.Number.Uint64()-1)
|
newh = pool.chain.GetHeader(newh.ParentHash, newh.Number.Uint64()-1)
|
||||||
if newh == nil {
|
if newh == nil {
|
||||||
@ -254,8 +254,8 @@ func (pool *TxPool) setNewHead(ctx context.Context, newHeader *types.Header) (tx
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if oldh.GetNumberU64() < pool.clearIdx {
|
if oldh.Number.Uint64() < pool.clearIdx {
|
||||||
pool.clearIdx = oldh.GetNumberU64()
|
pool.clearIdx = oldh.Number.Uint64()
|
||||||
}
|
}
|
||||||
// roll back old blocks
|
// roll back old blocks
|
||||||
for _, hash := range oldHashes {
|
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)
|
// check mined txs of new blocks (array is in reversed order)
|
||||||
for i := len(newHashes) - 1; i >= 0; i-- {
|
for i := len(newHashes) - 1; i >= 0; i-- {
|
||||||
hash := newHashes[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
|
return txc, err
|
||||||
}
|
}
|
||||||
pool.head = hash
|
pool.head = hash
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear old mined tx entries of old blocks
|
// 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
|
idx2 := idx - txPermanent
|
||||||
for i := pool.clearIdx; i < idx2; i++ {
|
for i := pool.clearIdx; i < idx2; i++ {
|
||||||
hash := core.GetCanonicalHash(pool.chainDb, 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) SetDepth(i int) { self.depth = i }
|
||||||
func (self *VMEnv) GetHash(n uint64) common.Hash {
|
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) {
|
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()
|
return header.Hash()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user