mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-26 13:40:05 +00:00
35fcd3a829
* implemented bor consensus * add bor flags to default * change bucket into snapshot to clique * enable stateSync * bypass reciept checks * fix receipt calculation and bor logs * fix: contract call wrt bor * Update mumbai config * Add: bor-mainnet flag and config * Add bor consensus to integration * use header coinbase in block context * london fork mumbai changes * fix genesis error * Jaipur fork for mumbai * add sysCall to verifyHeader * added bor related rpc method implementation * added bor specific rpc extensions * fixes in snapshot implementation, major refactor for bor rpc * modify consensus specific db path for bor * fix: remove parallel compute for get root hash rpc method * Added bor-receipt flow * Use turbo-bor-lib and bor tables * Use bor table in RPC snapshot * Update README.md * Update README.md * Update README.md * Update README.md * update rpc readme * link rpc docs in readme * Update Readme * Update Readme * move erigon namespace rpc methods to eth * rm: erigon namespace * rm: erigon namespace, update list of available rpc methods, add example * fix: binary name in rpc readme * fix: max db size * Add london to bor-mainnet * updated node.go * add system req to readme * golang version fix readme * added networknames in correct place * nil * ran gofmt * erigon * fixed fake.go * dont need turbor-lib * old readme * fixing readme * half * other half * changed return * fixing return * fixed return * fixed flags * gofmt * merge with devel * latest erigon-lib * fixed context.coinbase * took out syscall * fixed params in hash * bor type now is consensus.Engine * parlia is consensus.Engine * missing arg and repeated importation * repeated importation * fixed eth_receipts.go * deleted duplicate issuance * part of consensus.Engine type * added eth_api issuance * networkname * added erigon_system file * fork struct taken out * added erigon block * getLogByHash for erigonImpl * gofmt * fixed lint * ops * gofmt * gofmt * added APIImple functions * fixed clique test * took out print * fixed state added balance * fixed README * fixed rpcDaemon README * fixed integration README * updated blockchain.go * lint * added bor back into blockchain.go * took out comment * lint * updated daemon * updated wtb * removed duplicate * removed VerifyHeaders * prevent use of wrong Transfer * fixed state_processor.go * fixed state_transition.go * fixed headers * returning err * error handling in bor read tx look up * put for txLookUp * dealing with error * lint * traces * more traces * fixed receipt in execution * getTrasanction receipt for bor or others * nil * lint * ops * deleted syscall * took out else * Merge branch 'devel * tests syscalls * changed borReceipt to receipt * reset header algos * arguments fix * took out prefixes * lint * erigon-named * borReceiptKey = blocknumber * reverts e3b60c2e159d03efcb855f7ab3da5a098dd60c33. * correct hashing tx * dont need it here * lint * added txlookup for bor * change to uint256 * outputs for isBor * wrapper * added isBor and isParlia * isBor * fixed BorTransfer * not readBody * correct prefix * added blockNum * added readStorageBody * readStorageBody * lint * got rid of unnecessary bor_receipt func * onlny if bor * use clone * append * writeToSlice * added isBor flag * fixed writeToSlice * normal sorting * lint * Reset erigon-snapshots * Move bor prefix into if Co-authored-by: Krishna Upadhyaya <krishnau1604@gmail.com> Co-authored-by: Manav Darji <manavdarji.india@gmail.com> Co-authored-by: Uttam Singh <uttamkhanduja@yahoo.in> Co-authored-by: Giulio Rebuffo <giulio.rebuffo@gmail.com> Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
157 lines
4.8 KiB
Go
157 lines
4.8 KiB
Go
package commands
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/ledgerwatch/erigon-lib/kv"
|
|
"github.com/ledgerwatch/erigon/common"
|
|
"github.com/ledgerwatch/erigon/consensus/bor"
|
|
"github.com/ledgerwatch/erigon/core/rawdb"
|
|
"github.com/ledgerwatch/erigon/core/types"
|
|
"github.com/ledgerwatch/erigon/crypto"
|
|
"github.com/ledgerwatch/erigon/params"
|
|
"github.com/ledgerwatch/erigon/rpc"
|
|
)
|
|
|
|
const (
|
|
checkpointInterval = 1024 // Number of blocks after which vote snapshots are saved to db
|
|
)
|
|
|
|
var (
|
|
extraVanity = 32 // Fixed number of extra-data prefix bytes reserved for signer vanity
|
|
extraSeal = 65 // Fixed number of extra-data suffix bytes reserved for signer seal
|
|
)
|
|
|
|
var (
|
|
// errUnknownBlock is returned when the list of signers is requested for a block
|
|
// that is not part of the local blockchain.
|
|
errUnknownBlock = errors.New("unknown block")
|
|
|
|
// errMissingSignature is returned if a block's extra-data section doesn't seem
|
|
// to contain a 65 byte secp256k1 signature.
|
|
errMissingSignature = errors.New("extra-data 65 byte signature suffix missing")
|
|
|
|
// errOutOfRangeChain is returned if an authorization list is attempted to
|
|
// be modified via out-of-range or non-contiguous headers.
|
|
errOutOfRangeChain = errors.New("out of range or non-contiguous chain")
|
|
|
|
// errMissingVanity is returned if a block's extra-data section is shorter than
|
|
// 32 bytes, which is required to store the signer vanity.
|
|
errMissingVanity = errors.New("extra-data 32 byte vanity prefix missing")
|
|
)
|
|
|
|
// getHeaderByNumber returns a block's header given a block number ignoring the block's transaction and uncle list (may be faster).
|
|
// derived from erigon_getHeaderByNumber implementation (see ./erigon_block.go)
|
|
func getHeaderByNumber(number rpc.BlockNumber, api *BorImpl, tx kv.Tx) (*types.Header, error) {
|
|
// Pending block is only known by the miner
|
|
if number == rpc.PendingBlockNumber {
|
|
block := api.pendingBlock()
|
|
if block == nil {
|
|
return nil, nil
|
|
}
|
|
return block.Header(), nil
|
|
}
|
|
|
|
blockNum, err := getBlockNumber(number, tx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
header := rawdb.ReadHeaderByNumber(tx, blockNum)
|
|
if header == nil {
|
|
return nil, fmt.Errorf("block header not found: %d", blockNum)
|
|
}
|
|
|
|
return header, nil
|
|
}
|
|
|
|
// getHeaderByHash returns a block's header given a block's hash.
|
|
// derived from erigon_getHeaderByHash implementation (see ./erigon_block.go)
|
|
func getHeaderByHash(tx kv.Tx, hash common.Hash) (*types.Header, error) {
|
|
header, err := rawdb.ReadHeaderByHash(tx, hash)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if header == nil {
|
|
return nil, fmt.Errorf("block header not found: %s", hash.String())
|
|
}
|
|
|
|
return header, nil
|
|
}
|
|
|
|
// ecrecover extracts the Ethereum account address from a signed header.
|
|
func ecrecover(header *types.Header, c *params.BorConfig) (common.Address, error) {
|
|
// Retrieve the signature from the header extra-data
|
|
if len(header.Extra) < extraSeal {
|
|
return common.Address{}, errMissingSignature
|
|
}
|
|
signature := header.Extra[len(header.Extra)-extraSeal:]
|
|
|
|
// Recover the public key and the Ethereum address
|
|
pubkey, err := crypto.Ecrecover(bor.SealHash(header, c).Bytes(), signature)
|
|
if err != nil {
|
|
return common.Address{}, err
|
|
}
|
|
var signer common.Address
|
|
copy(signer[:], crypto.Keccak256(pubkey[1:])[12:])
|
|
|
|
return signer, nil
|
|
}
|
|
|
|
// validateHeaderExtraField validates that the extra-data contains both the vanity and signature.
|
|
// header.Extra = header.Vanity + header.ProducerBytes (optional) + header.Seal
|
|
func validateHeaderExtraField(extraBytes []byte) error {
|
|
if len(extraBytes) < extraVanity {
|
|
return errMissingVanity
|
|
}
|
|
if len(extraBytes) < extraVanity+extraSeal {
|
|
return errMissingSignature
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// validatorContains checks for a validator in given validator set
|
|
func validatorContains(a []*bor.Validator, x *bor.Validator) (*bor.Validator, bool) {
|
|
for _, n := range a {
|
|
if bytes.Equal(n.Address.Bytes(), x.Address.Bytes()) {
|
|
return n, true
|
|
}
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
// getUpdatedValidatorSet applies changes to a validator set and returns a new validator set
|
|
func getUpdatedValidatorSet(oldValidatorSet *ValidatorSet, newVals []*bor.Validator) *ValidatorSet {
|
|
v := oldValidatorSet
|
|
oldVals := v.Validators
|
|
|
|
var changes []*bor.Validator
|
|
for _, ov := range oldVals {
|
|
if f, ok := validatorContains(newVals, ov); ok {
|
|
ov.VotingPower = f.VotingPower
|
|
} else {
|
|
ov.VotingPower = 0
|
|
}
|
|
|
|
changes = append(changes, ov)
|
|
}
|
|
|
|
for _, nv := range newVals {
|
|
if _, ok := validatorContains(changes, nv); !ok {
|
|
changes = append(changes, nv)
|
|
}
|
|
}
|
|
|
|
v.UpdateWithChangeSet(changes)
|
|
return v
|
|
}
|
|
|
|
// author returns the Ethereum address recovered
|
|
// from the signature in the header's extra-data section.
|
|
func author(api *BorImpl, tx kv.Tx, header *types.Header) (common.Address, error) {
|
|
config, _ := api.BaseAPI.chainConfig(tx)
|
|
return ecrecover(header, config.Bor)
|
|
}
|