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 009b40b
Show file tree
Hide file tree
Showing 12 changed files with 730 additions and 745 deletions.
6 changes: 3 additions & 3 deletions command/bridge/helper/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

polybftsecrets "github.com/0xPolygon/polygon-edge/command/secrets/init"
"github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi"
systemstate "github.com/0xPolygon/polygon-edge/consensus/polybft/system_state"
"github.com/0xPolygon/polygon-edge/consensus/polybft/validator"
polybftWallet "github.com/0xPolygon/polygon-edge/consensus/polybft/wallet"
"github.com/0xPolygon/polygon-edge/contracts"
"github.com/0xPolygon/polygon-edge/crypto"
Expand Down Expand Up @@ -154,7 +154,7 @@ func GetECDSAKey(privateKey, accountDir, accountConfig string) (crypto.Key, erro
// GetValidatorInfo queries SupernetManager smart contract on root
// and retrieves validator info for given address
func GetValidatorInfo(validatorAddr types.Address, supernetManagerAddr, stakeManagerAddr types.Address,
txRelayer txrelayer.TxRelayer) (*systemstate.ValidatorInfo, error) {
txRelayer txrelayer.TxRelayer) (*validator.ValidatorInfo, error) {
caller := contracts.SystemCaller
getValidatorMethod := contractsapi.StakeManager.Abi.GetMethod("stakeOf")

Expand Down Expand Up @@ -189,7 +189,7 @@ func GetValidatorInfo(validatorAddr types.Address, supernetManagerAddr, stakeMan
}

//nolint:forcetypeassert
validatorInfo := &systemstate.ValidatorInfo{
validatorInfo := &validator.ValidatorInfo{
Address: validatorAddr,
IsActive: innerMap["isActive"].(bool),
IsWhitelisted: innerMap["isWhitelisted"].(bool),
Expand Down
6 changes: 3 additions & 3 deletions command/validator/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

polybftsecrets "github.com/0xPolygon/polygon-edge/command/secrets/init"
"github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi"
systemstate "github.com/0xPolygon/polygon-edge/consensus/polybft/system_state"
"github.com/0xPolygon/polygon-edge/consensus/polybft/validator"
"github.com/0xPolygon/polygon-edge/consensus/polybft/wallet"
"github.com/0xPolygon/polygon-edge/contracts"
"github.com/0xPolygon/polygon-edge/helper/common"
Expand Down Expand Up @@ -59,7 +59,7 @@ func GetAccountFromDir(accountDir string) (*wallet.Account, error) {
// GetValidatorInfo queries CustomSupernetManager, StakeManager and RewardPool smart contracts
// to retrieve validator info for given address
func GetValidatorInfo(validatorAddr types.Address,
childRelayer txrelayer.TxRelayer) (*systemstate.ValidatorInfo, error) {
childRelayer txrelayer.TxRelayer) (*validator.ValidatorInfo, error) {
getValidatorMethod := contractsapi.StakeManager.Abi.GetMethod("getValidator")

encode, err := getValidatorMethod.Encode([]interface{}{validatorAddr})
Expand Down Expand Up @@ -93,7 +93,7 @@ func GetValidatorInfo(validatorAddr types.Address,
}

//nolint:forcetypeassert
validatorInfo := &systemstate.ValidatorInfo{
validatorInfo := &validator.ValidatorInfo{
Address: validatorAddr,
IsActive: innerMap["isActive"].(bool),
IsWhitelisted: innerMap["isWhitelisted"].(bool),
Expand Down
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
47 changes: 3 additions & 44 deletions consensus/polybft/blockchain/blockchain_wrapper.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package blockchain

import (
"errors"
"fmt"
"math/big"
"time"

"github.com/hashicorp/go-hclog"
Expand All @@ -15,18 +13,13 @@ 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"
)

const (
consensusSource = "consensus"
)

var (
errSendTxnUnsupported = errors.New("system state does not support send transactions")
)

var _ Blockchain = &BlockchainWrapper{}

type BlockchainWrapper struct {
Expand Down Expand Up @@ -101,12 +94,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 @@ -154,43 +147,9 @@ func (p *BlockchainWrapper) UnubscribeEvents(subscription blockchain.Subscriptio
}

func (p *BlockchainWrapper) GetChainID() uint64 {
return uint64(p.blockchain.Config().ChainID)
return uint64(p.blockchain.Config().ChainID) //nolint:gosec
}

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
10 changes: 0 additions & 10 deletions consensus/polybft/system_state/system_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ var (
errSendTxnUnsupported = errors.New("system state does not support send transactions")
)

// ValidatorInfo is data transfer object which holds validator information,
// provided by smart contract
type ValidatorInfo struct {
Stake *big.Int `json:"stake"`
WithdrawableRewards *big.Int `json:"withdrawableRewards"`
Address types.Address `json:"address"`
IsActive bool `json:"isActive"`
IsWhitelisted bool `json:"isWhitelisted"`
}

type ChainType int

const (
Expand Down
Loading

0 comments on commit 009b40b

Please sign in to comment.