mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-28 07:36:44 +00:00
fix: use hash instead of number for eth call
This commit is contained in:
parent
264551cbc1
commit
43e41773fa
2 changed files with 14 additions and 8 deletions
|
|
@ -455,7 +455,7 @@ func (c *Bor) snapshot(chain consensus.ChainHeaderReader, number uint64, hash co
|
|||
hash := checkpoint.Hash()
|
||||
|
||||
// get validators and current span
|
||||
validators, err := c.GetCurrentValidators(number, number+1)
|
||||
validators, err := c.GetCurrentValidators(hash, number+1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -609,7 +609,7 @@ func (c *Bor) Prepare(chain consensus.ChainHeaderReader, header *types.Header) e
|
|||
|
||||
// get validator set if number
|
||||
if (number+1)%c.config.Sprint == 0 {
|
||||
newValidators, err := c.GetCurrentValidators(snap.Number, number+1)
|
||||
newValidators, err := c.GetCurrentValidators(header.ParentHash, number+1)
|
||||
if err != nil {
|
||||
return errors.New("unknown validators")
|
||||
}
|
||||
|
|
@ -853,6 +853,9 @@ func (c *Bor) GetCurrentSpan(headerHash common.Hash) (*Span, error) {
|
|||
// method
|
||||
method := "getCurrentSpan"
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
data, err := c.validatorSetABI.Pack(method)
|
||||
if err != nil {
|
||||
log.Error("Unable to pack tx for getCurrentSpan", "error", err)
|
||||
|
|
@ -862,7 +865,7 @@ func (c *Bor) GetCurrentSpan(headerHash common.Hash) (*Span, error) {
|
|||
msgData := (hexutil.Bytes)(data)
|
||||
toAddress := common.HexToAddress(c.config.ValidatorContract)
|
||||
gas := (hexutil.Uint64)(uint64(math.MaxUint64 / 2))
|
||||
result, err := c.ethAPI.Call(context.Background(), ethapi.CallArgs{
|
||||
result, err := c.ethAPI.Call(ctx, ethapi.CallArgs{
|
||||
Gas: &gas,
|
||||
To: &toAddress,
|
||||
Data: &msgData,
|
||||
|
|
@ -892,13 +895,16 @@ func (c *Bor) GetCurrentSpan(headerHash common.Hash) (*Span, error) {
|
|||
}
|
||||
|
||||
// GetCurrentValidators get current validators
|
||||
func (c *Bor) GetCurrentValidators(snapshotNumber uint64, blockNumber uint64) ([]*Validator, error) {
|
||||
func (c *Bor) GetCurrentValidators(headerHash common.Hash, blockNumber uint64) ([]*Validator, error) {
|
||||
// block
|
||||
blockNr := rpc.BlockNumber(snapshotNumber)
|
||||
blockNr := rpc.BlockNumberOrHashWithHash(headerHash, false)
|
||||
|
||||
// method
|
||||
method := "getBorValidators"
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
data, err := c.validatorSetABI.Pack(method, big.NewInt(0).SetUint64(blockNumber))
|
||||
if err != nil {
|
||||
log.Error("Unable to pack tx for getValidator", "error", err)
|
||||
|
|
@ -909,11 +915,11 @@ func (c *Bor) GetCurrentValidators(snapshotNumber uint64, blockNumber uint64) ([
|
|||
msgData := (hexutil.Bytes)(data)
|
||||
toAddress := common.HexToAddress(c.config.ValidatorContract)
|
||||
gas := (hexutil.Uint64)(uint64(math.MaxUint64 / 2))
|
||||
result, err := c.ethAPI.Call(context.Background(), ethapi.CallArgs{
|
||||
result, err := c.ethAPI.Call(ctx, ethapi.CallArgs{
|
||||
Gas: &gas,
|
||||
To: &toAddress,
|
||||
Data: &msgData,
|
||||
}, rpc.BlockNumberOrHash{BlockNumber: &blockNr}, nil)
|
||||
}, blockNr, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
// return nil, err
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ func TestInsertingSpanSizeBlocks(t *testing.T) {
|
|||
}
|
||||
|
||||
assert.True(t, h.AssertCalled(t, "FetchWithRetry", spanPath, ""))
|
||||
validators, err := _bor.GetCurrentValidators(sprintSize, spanSize) // check validator set at the first block of new span
|
||||
validators, err := _bor.GetCurrentValidators(block.Hash(), spanSize) // check validator set at the first block of new span
|
||||
if err != nil {
|
||||
t.Fatalf("%s", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue