Skip to content

Commit

Permalink
Merge pull request #37 from ethereum-pocr/merging-paravin-v1.10.26
Browse files Browse the repository at this point in the history
Merge for new Consensus (Kerleano v2.0)
  • Loading branch information
guenoledc authored Dec 6, 2022
2 parents 4f4c660 + 69bbb51 commit 51f9d32
Show file tree
Hide file tree
Showing 48 changed files with 1,555 additions and 862 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-and-publish-geth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

jobs:
build:
runs-on: self-hosted
runs-on: ubuntu-20.04

container:
image: golang:latest
Expand All @@ -30,7 +30,7 @@ jobs:
- name: publish geth latest version
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
repo_token: ${{ github.token }}
file: build/bin/geth
asset_name: geth
tag: ${{ github.ref }}
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallM
vmEnv := vm.NewEVM(evmContext, txContext, stateDB, b.config, vm.Config{NoBaseFee: true})
gasPool := new(core.GasPool).AddGas(math.MaxUint64)

return core.NewStateTransition(vmEnv, msg, gasPool).TransitionDb()
return core.NewStateTransition(vmEnv, msg, gasPool).TransitionDb(b.blockchain.Engine())
}

// SendTransaction updates the pending block to include the given transaction.
Expand Down
1 change: 0 additions & 1 deletion consensus/beacon/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"errors"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/misc"
Expand Down
16 changes: 8 additions & 8 deletions consensus/clique/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (api *API) GetSnapshot(number *rpc.BlockNumber) (*Snapshot, error) {
if header == nil {
return nil, errUnknownBlock
}
return api.Clique.snapshot(api.Chain, header.Number.Uint64(), header.Hash(), nil)
return api.Clique.Snapshot(api.Chain, header.Number.Uint64(), header.Hash(), nil)
}

// GetSnapshotAtHash retrieves the state snapshot at a given block.
Expand All @@ -57,7 +57,7 @@ func (api *API) GetSnapshotAtHash(hash common.Hash) (*Snapshot, error) {
if header == nil {
return nil, errUnknownBlock
}
return api.Clique.snapshot(api.Chain, header.Number.Uint64(), header.Hash(), nil)
return api.Clique.Snapshot(api.Chain, header.Number.Uint64(), header.Hash(), nil)
}

// GetSigners retrieves the list of authorized signers at the specified block.
Expand All @@ -73,11 +73,11 @@ func (api *API) GetSigners(number *rpc.BlockNumber) ([]common.Address, error) {
if header == nil {
return nil, errUnknownBlock
}
snap, err := api.Clique.snapshot(api.Chain, header.Number.Uint64(), header.Hash(), nil)
snap, err := api.Clique.Snapshot(api.Chain, header.Number.Uint64(), header.Hash(), nil)
if err != nil {
return nil, err
}
return snap.signers(), nil
return snap.GetSigners(), nil
}

// GetSignersAtHash retrieves the list of authorized signers at the specified block.
Expand All @@ -86,11 +86,11 @@ func (api *API) GetSignersAtHash(hash common.Hash) ([]common.Address, error) {
if header == nil {
return nil, errUnknownBlock
}
snap, err := api.Clique.snapshot(api.Chain, header.Number.Uint64(), header.Hash(), nil)
snap, err := api.Clique.Snapshot(api.Chain, header.Number.Uint64(), header.Hash(), nil)
if err != nil {
return nil, err
}
return snap.signers(), nil
return snap.GetSigners(), nil
}

// Proposals returns the current proposals the node tries to uphold and vote on.
Expand Down Expand Up @@ -140,12 +140,12 @@ func (api *API) Status() (*status, error) {
diff = uint64(0)
optimals = 0
)
snap, err := api.Clique.snapshot(api.Chain, header.Number.Uint64(), header.Hash(), nil)
snap, err := api.Clique.Snapshot(api.Chain, header.Number.Uint64(), header.Hash(), nil)
if err != nil {
return nil, err
}
var (
signers = snap.signers()
signers = snap.GetSigners()
end = header.Number.Uint64()
start = end - numBlocks
)
Expand Down
23 changes: 15 additions & 8 deletions consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ var (
// SignerFn hashes and signs the data to be signed by a backing account.
type SignerFn func(signer accounts.Account, mimeType string, message []byte) ([]byte, error)

// Declare an interface for the Clique engine
type CliqueEngine interface {
consensus.Engine

Authorize(signer common.Address, signFn SignerFn)
}

// ecrecover extracts the Ethereum account address from a signed header.
func ecrecover(header *types.Header, sigcache *lru.ARCCache) (common.Address, error) {
// If the signature's already cached, return that
Expand Down Expand Up @@ -346,14 +353,14 @@ func (c *Clique) verifyCascadingFields(chain consensus.ChainHeaderReader, header
return err
}
// Retrieve the snapshot needed to verify this header and cache it
snap, err := c.snapshot(chain, number-1, header.ParentHash, parents)
snap, err := c.Snapshot(chain, number-1, header.ParentHash, parents)
if err != nil {
return err
}
// If the block is a checkpoint block, verify the signer list
if number%c.config.Epoch == 0 {
signers := make([]byte, len(snap.Signers)*common.AddressLength)
for i, signer := range snap.signers() {
for i, signer := range snap.GetSigners() {
copy(signers[i*common.AddressLength:], signer[:])
}
extraSuffix := len(header.Extra) - extraSeal
Expand All @@ -365,8 +372,8 @@ func (c *Clique) verifyCascadingFields(chain consensus.ChainHeaderReader, header
return c.verifySeal(snap, header, parents)
}

// snapshot retrieves the authorization snapshot at a given point in time.
func (c *Clique) snapshot(chain consensus.ChainHeaderReader, number uint64, hash common.Hash, parents []*types.Header) (*Snapshot, error) {
// Snapshot retrieves the authorization Snapshot at a given point in time.
func (c *Clique) Snapshot(chain consensus.ChainHeaderReader, number uint64, hash common.Hash, parents []*types.Header) (*Snapshot, error) {
// Search for a snapshot in memory or on disk for checkpoints
var (
headers []*types.Header
Expand Down Expand Up @@ -503,7 +510,7 @@ func (c *Clique) Prepare(chain consensus.ChainHeaderReader, header *types.Header

number := header.Number.Uint64()
// Assemble the voting snapshot to check which votes make sense
snap, err := c.snapshot(chain, number-1, header.ParentHash, nil)
snap, err := c.Snapshot(chain, number-1, header.ParentHash, nil)
if err != nil {
return err
}
Expand Down Expand Up @@ -542,7 +549,7 @@ func (c *Clique) Prepare(chain consensus.ChainHeaderReader, header *types.Header
header.Extra = header.Extra[:extraVanity]

if number%c.config.Epoch == 0 {
for _, signer := range snap.signers() {
for _, signer := range snap.GetSigners() {
header.Extra = append(header.Extra, signer[:]...)
}
}
Expand Down Expand Up @@ -611,7 +618,7 @@ func (c *Clique) Seal(chain consensus.ChainHeaderReader, block *types.Block, res
c.lock.RUnlock()

// Bail out if we're unauthorized to sign a block
snap, err := c.snapshot(chain, number-1, header.ParentHash, nil)
snap, err := c.Snapshot(chain, number-1, header.ParentHash, nil)
if err != nil {
return err
}
Expand Down Expand Up @@ -666,7 +673,7 @@ func (c *Clique) Seal(chain consensus.ChainHeaderReader, block *types.Block, res
// * DIFF_NOTURN(2) if BLOCK_NUMBER % SIGNER_COUNT != SIGNER_INDEX
// * DIFF_INTURN(1) if BLOCK_NUMBER % SIGNER_COUNT == SIGNER_INDEX
func (c *Clique) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int {
snap, err := c.snapshot(chain, parent.Number.Uint64(), parent.Hash(), nil)
snap, err := c.Snapshot(chain, parent.Number.Uint64(), parent.Hash(), nil)
if err != nil {
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions consensus/clique/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
return snap, nil
}

// signers retrieves the list of authorized signers in ascending order.
func (s *Snapshot) signers() []common.Address {
// GetSigners retrieves the list of authorized GetSigners in ascending order.
func (s *Snapshot) GetSigners() []common.Address {
sigs := make([]common.Address, 0, len(s.Signers))
for sig := range s.Signers {
sigs = append(sigs, sig)
Expand All @@ -318,7 +318,7 @@ func (s *Snapshot) signers() []common.Address {

// inturn returns if a signer at a given block height is in-turn or not.
func (s *Snapshot) inturn(number uint64, signer common.Address) bool {
signers, offset := s.signers(), 0
signers, offset := s.GetSigners(), 0
for offset < len(signers) && signers[offset] != signer {
offset++
}
Expand Down
4 changes: 2 additions & 2 deletions consensus/clique/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ func TestClique(t *testing.T) {
// No failure was produced or requested, generate the final voting snapshot
head := blocks[len(blocks)-1]

snap, err := engine.snapshot(chain, head.NumberU64(), head.Hash(), nil)
snap, err := engine.Snapshot(chain, head.NumberU64(), head.Hash(), nil)
if err != nil {
t.Errorf("test %d: failed to retrieve voting snapshot: %v", i, err)
continue
Expand All @@ -492,7 +492,7 @@ func TestClique(t *testing.T) {
}
}
}
result := snap.signers()
result := snap.GetSigners()
if len(result) != len(signers) {
t.Errorf("test %d: signers mismatch: have %x, want %x", i, result, signers)
continue
Expand Down
69 changes: 0 additions & 69 deletions consensus/cliquepcr/carbonfootprint_test.go

This file was deleted.

Loading

0 comments on commit 51f9d32

Please sign in to comment.