Skip to content

Commit

Permalink
comment fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal committed Sep 30, 2024
1 parent a427654 commit 17c61a4
Show file tree
Hide file tree
Showing 7 changed files with 701 additions and 718 deletions.
21 changes: 20 additions & 1 deletion consensus/polybft/blockchain/block_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,24 @@ import (
"github.com/hashicorp/go-hclog"
)

// BlockBuilder is an interface that defines functions used for block building
type BlockBuilder interface {
// Reset initializes block builder before adding transactions and actual block building
Reset() error
// WriteTx applies given transaction to the state.
// if transaction apply fails, it reverts the saved snapshot.
WriteTx(*types.Transaction) error
// Fill fills the block with transactions from the txpool
Fill()
// Block returns the built block if nil, it is not built yet
Build(func(h *types.Header)) (*types.FullBlock, error)
// GetState returns Transition reference
GetState() *state.Transition
// Receipts returns the collection of transaction receipts for given block
Receipts() []*types.Receipt
}

// blockchain is an interface that wraps the methods called on blockchain
// Blockchain is an interface that wraps the functions called on blockchain
type Blockchain interface {
// CurrentHeader returns the header of blockchain block head
CurrentHeader() *types.Header
Expand Down Expand Up @@ -67,16 +75,27 @@ type Blockchain interface {
GetReceiptsByHash(hash types.Hash) ([]*types.Receipt, error)
}

// TxPool is an interface that defines functions used for transaction pool
type TxPool interface {
// Prepare prepares the tx pool for the next block
Prepare()
// Length returns the number of transactions in the pool
Length() uint64
// Peek returns the next transaction in the pool
Peek() *types.Transaction
// Pop removes the transaction from the pool
Pop(*types.Transaction)
// Drop removes the transaction from the pool
Drop(*types.Transaction)
// Demote demotes the transaction
Demote(*types.Transaction)
// SetSealing sets the sealing (isValidator) flag in tx pool
SetSealing(bool)
// ResetWithBlock resets the tx pool with the given block
ResetWithBlock(*types.Block)
// ReinsertProposed reinserts the proposed transaction
ReinsertProposed()
// ClearProposed clears the proposed transaction
ClearProposed()
}

Expand Down
40 changes: 2 additions & 38 deletions consensus/polybft/blockchain/blockchain_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package blockchain
import (
"errors"
"fmt"
"math/big"
"time"

"github.com/hashicorp/go-hclog"
Expand All @@ -15,7 +14,6 @@ import (
"github.com/0xPolygon/polygon-edge/contracts"
"github.com/0xPolygon/polygon-edge/state"
"github.com/0xPolygon/polygon-edge/types"
"github.com/Ethernal-Tech/ethgo"
"github.com/Ethernal-Tech/ethgo/contract"
)

Expand Down Expand Up @@ -101,12 +99,12 @@ func (p *BlockchainWrapper) GetStateProviderForBlock(header *types.Header) (cont
return nil, err
}

return NewStateProvider(transition), nil
return systemstate.NewStateProvider(transition), nil
}

// GetStateProvider returns a reference to make queries to the provided state
func (p *BlockchainWrapper) GetStateProvider(transition *state.Transition) contract.Provider {
return NewStateProvider(transition)
return systemstate.NewStateProvider(transition)
}

// GetHeaderByNumber is an implementation of blockchainBackend interface
Expand Down Expand Up @@ -160,37 +158,3 @@ func (p *BlockchainWrapper) GetChainID() uint64 {
func (p *BlockchainWrapper) GetReceiptsByHash(hash types.Hash) ([]*types.Receipt, error) {
return p.blockchain.GetReceiptsByHash(hash)
}

var _ contract.Provider = &stateProvider{}

type stateProvider struct {
transition *state.Transition
}

// NewStateProvider initializes EVM against given state and chain config and returns stateProvider instance
// which is an abstraction for smart contract calls
func NewStateProvider(transition *state.Transition) contract.Provider {
return &stateProvider{transition: transition}
}

// Call implements the contract.Provider interface to make contract calls directly to the state
func (s *stateProvider) Call(addr ethgo.Address, input []byte, opts *contract.CallOpts) ([]byte, error) {
result := s.transition.Call2(
contracts.SystemCaller,
types.Address(addr),
input,
big.NewInt(0),
10000000,
)
if result.Failed() {
return nil, result.Err
}

return result.ReturnValue, nil
}

// Txn is part of the contract.Provider interface to make Ethereum transactions. We disable this function
// since the system state does not make any transaction
func (s *stateProvider) Txn(_ ethgo.Address, _ ethgo.Key, _ []byte) (contract.Txn, error) {
return nil, errSendTxnUnsupported
}
4 changes: 2 additions & 2 deletions consensus/polybft/bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"google.golang.org/protobuf/proto"
)

// topic is an interface for p2p message gossiping
// Topic is an interface for p2p message gossiping
type Topic interface {
Publish(obj proto.Message) error
Subscribe(handler func(obj interface{}, from peer.ID)) error
Expand Down Expand Up @@ -50,7 +50,7 @@ func (d *DummyBridge) BridgeBatch(pendingBlockNumber uint64) ([]*BridgeBatchSign
}
func (d *DummyBridge) InsertEpoch(epoch uint64, tx *bolt.Tx) error { return nil }

// newBridge creates a new instance of bridge
// NewBridge creates a new instance of bridge
func NewBridge(runtime Runtime,
state *state.State,
runtimeConfig *config.Runtime,
Expand Down
2 changes: 1 addition & 1 deletion consensus/polybft/config/runtime_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/0xPolygon/polygon-edge/consensus/polybft/wallet"
)

// RuntimeConfig is a struct that holds configuration data for given consensus runtime
// Runtime is a struct that holds configuration data for given consensus runtime
type Runtime struct {
ChainParams *chain.Params
GenesisConfig *PolyBFT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ func newTestState(tb testing.TB) *ProposerSnapshotStore {
tb.Fatal(err)
}

stakeSTore, err := newProposerSnapshotStore(db, nil)
proposerSnapshotStore, err := newProposerSnapshotStore(db, nil)
if err != nil {
tb.Fatal(err)
}

return stakeSTore
return proposerSnapshotStore
}

func TestState_getProposerSnapshot_writeProposerSnapshot(t *testing.T) {
Expand Down
Loading

0 comments on commit 17c61a4

Please sign in to comment.