-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BEP-341: Validators can produce consecutive blocks
- Loading branch information
Showing
10 changed files
with
288 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package parlia | ||
|
||
import ( | ||
"context" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/ethereum/go-ethereum/common/math" | ||
"github.com/ethereum/go-ethereum/core/systemcontracts" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/internal/ethapi" | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/ethereum/go-ethereum/rpc" | ||
) | ||
|
||
func (p *Parlia) getTurnTerm(header *types.Header) (turnTerm *big.Int, err error) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
method := "getTurnTerm" | ||
toAddress := common.HexToAddress(systemcontracts.ValidatorContract) | ||
gas := (hexutil.Uint64)(uint64(math.MaxUint64 / 2)) | ||
|
||
data, err := p.validatorSetABI.Pack(method) | ||
if err != nil { | ||
log.Error("Unable to pack tx for getTurnTerm", "error", err) | ||
return nil, err | ||
} | ||
msgData := (hexutil.Bytes)(data) | ||
|
||
blockNr := rpc.BlockNumberOrHashWithHash(header.Hash(), false) | ||
result, err := p.ethAPI.Call(ctx, ethapi.TransactionArgs{ | ||
Gas: &gas, | ||
To: &toAddress, | ||
Data: &msgData, | ||
}, &blockNr, nil, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := p.validatorSetABI.UnpackIntoInterface(&turnTerm, method, result); err != nil { | ||
return nil, err | ||
} | ||
|
||
return turnTerm, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.