Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate different features in polybft package to separate packages #383

Merged
merged 5 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ issues:
- unparam
- lll
- forcetypeassert
- path: mocks.go
linters:
- gosec
- unparam
- lll
- forcetypeassert
- path: gen_sc_data\.go
linters:
- wsl
Expand Down
10 changes: 5 additions & 5 deletions command/bridge/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/0xPolygon/polygon-edge/command"
"github.com/0xPolygon/polygon-edge/command/bridge/helper"
cmdHelper "github.com/0xPolygon/polygon-edge/command/helper"
"github.com/0xPolygon/polygon-edge/consensus/polybft"
polycfg "github.com/0xPolygon/polygon-edge/consensus/polybft/config"
goran-ethernal marked this conversation as resolved.
Show resolved Hide resolved
"github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi"
"github.com/0xPolygon/polygon-edge/consensus/polybft/validator"
"github.com/0xPolygon/polygon-edge/crypto"
Expand All @@ -28,11 +28,11 @@ var (
params deployParams

// consensusCfg contains consensus protocol configuration parameters
consensusCfg polybft.PolyBFTConfig
consensusCfg polycfg.PolyBFT
)

type deploymentResultInfo struct {
BridgeCfg *polybft.BridgeConfig
BridgeCfg *polycfg.Bridge
CommandResults []command.CommandResult
}

Expand Down Expand Up @@ -194,7 +194,7 @@ func runCommand(cmd *cobra.Command, _ []string) {
}

// write updated consensus configuration
chainConfig.Params.Engine[polybft.ConsensusName] = consensusCfg
chainConfig.Params.Engine[polycfg.ConsensusName] = consensusCfg

if err := cmdHelper.WriteGenesisConfigToDisk(chainConfig, params.genesisPath); err != nil {
outputter.SetError(fmt.Errorf("failed to save chain configuration bridge data: %w", err))
Expand Down Expand Up @@ -241,7 +241,7 @@ func deployContracts(

var (
internalChainID = chainCfg.Params.ChainID
bridgeConfig = &polybft.BridgeConfig{JSONRPCEndpoint: params.externalRPCAddress}
bridgeConfig = &polycfg.Bridge{JSONRPCEndpoint: params.externalRPCAddress}
externalContracts []*contract
internalContracts []*contract
)
Expand Down
6 changes: 3 additions & 3 deletions command/bridge/deploy/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/0xPolygon/polygon-edge/chain"
"github.com/0xPolygon/polygon-edge/command"
"github.com/0xPolygon/polygon-edge/command/bridge/helper"
"github.com/0xPolygon/polygon-edge/consensus/polybft"
polycfg "github.com/0xPolygon/polygon-edge/consensus/polybft/config"
"github.com/0xPolygon/polygon-edge/consensus/polybft/validator"
"github.com/0xPolygon/polygon-edge/types"
)
Expand All @@ -41,8 +41,8 @@ func TestDeployContracts_NoPanics(t *testing.T) {

outputter := command.InitializeOutputter(GetCommand())
params.proxyContractsAdmin = "0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed"
consensusCfg = polybft.PolyBFTConfig{
NativeTokenConfig: &polybft.TokenConfig{
consensusCfg = polycfg.PolyBFT{
NativeTokenConfig: &polycfg.Token{
Name: "Test",
Symbol: "TST",
Decimals: 18,
Expand Down
50 changes: 25 additions & 25 deletions command/bridge/deploy/external_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"math/big"

"github.com/0xPolygon/polygon-edge/command"
"github.com/0xPolygon/polygon-edge/consensus/polybft"
polycfg "github.com/0xPolygon/polygon-edge/consensus/polybft/config"
"github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi"
"github.com/0xPolygon/polygon-edge/consensus/polybft/validator"
"github.com/0xPolygon/polygon-edge/contracts"
Expand All @@ -16,7 +16,7 @@ import (
)

// initExternalContracts initializes the external contracts
func initExternalContracts(bridgeCfg *polybft.BridgeConfig,
func initExternalContracts(bridgeCfg *polycfg.Bridge,
externalChainClient *jsonrpc.EthClient, externalChainID *big.Int) ([]*contract, error) {
externalContracts := make([]*contract, 0)

Expand All @@ -35,7 +35,7 @@ func initExternalContracts(bridgeCfg *polybft.BridgeConfig,
name: getContractName(false, erc20Name),
hasProxy: false,
artifact: contractsapi.RootERC20,
addressPopulatorFn: func(bc *polybft.BridgeConfig, dcr []*deployContractResult) {
addressPopulatorFn: func(bc *polycfg.Bridge, dcr []*deployContractResult) {
bc.ExternalNativeERC20Addr = dcr[0].Address
},
})
Expand All @@ -47,7 +47,7 @@ func initExternalContracts(bridgeCfg *polybft.BridgeConfig,
name: blsName,
hasProxy: true,
artifact: contractsapi.BLS,
addressPopulatorFn: func(bc *polybft.BridgeConfig, dcr []*deployContractResult) {
addressPopulatorFn: func(bc *polycfg.Bridge, dcr []*deployContractResult) {
bc.BLSAddress = dcr[1].Address
},
})
Expand All @@ -57,7 +57,7 @@ func initExternalContracts(bridgeCfg *polybft.BridgeConfig,
name: bn256G2Name,
hasProxy: true,
artifact: contractsapi.BLS256,
addressPopulatorFn: func(bc *polybft.BridgeConfig, dcr []*deployContractResult) {
addressPopulatorFn: func(bc *polycfg.Bridge, dcr []*deployContractResult) {
bc.BN256G2Address = dcr[1].Address
},
})
Expand All @@ -67,12 +67,12 @@ func initExternalContracts(bridgeCfg *polybft.BridgeConfig,
name: getContractName(false, gatewayName),
hasProxy: true,
artifact: contractsapi.Gateway,
addressPopulatorFn: func(bc *polybft.BridgeConfig, dcr []*deployContractResult) {
addressPopulatorFn: func(bc *polycfg.Bridge, dcr []*deployContractResult) {
bc.ExternalGatewayAddr = dcr[1].Address
},
initializeFn: func(fmt command.OutputFormatter, relayer txrelayer.TxRelayer,
genesisValidators []*validator.GenesisValidator,
config *polybft.BridgeConfig,
config *polycfg.Bridge,
key crypto.Key,
destinationChainID int64) error {
validatorSet, err := getValidatorSet(fmt, genesisValidators)
Expand All @@ -96,12 +96,12 @@ func initExternalContracts(bridgeCfg *polybft.BridgeConfig,
name: getContractName(false, erc20PredicateName),
hasProxy: true,
artifact: contractsapi.RootERC20Predicate,
addressPopulatorFn: func(bc *polybft.BridgeConfig, dcr []*deployContractResult) {
addressPopulatorFn: func(bc *polycfg.Bridge, dcr []*deployContractResult) {
bc.ExternalERC20PredicateAddr = dcr[1].Address
},
initializeFn: func(fmt command.OutputFormatter, relayer txrelayer.TxRelayer,
genesisValidators []*validator.GenesisValidator,
config *polybft.BridgeConfig,
config *polycfg.Bridge,
key crypto.Key,
destinationChainID int64) error {
input := &contractsapi.InitializeRootERC20PredicateFn{
Expand All @@ -123,12 +123,12 @@ func initExternalContracts(bridgeCfg *polybft.BridgeConfig,
name: getContractName(false, erc20MintablePredicateName),
hasProxy: true,
artifact: contractsapi.ChildERC20Predicate,
addressPopulatorFn: func(bc *polybft.BridgeConfig, dcr []*deployContractResult) {
addressPopulatorFn: func(bc *polycfg.Bridge, dcr []*deployContractResult) {
bc.ExternalMintableERC20PredicateAddr = dcr[1].Address
},
initializeFn: func(fmt command.OutputFormatter, relayer txrelayer.TxRelayer,
genesisValidators []*validator.GenesisValidator,
config *polybft.BridgeConfig,
config *polycfg.Bridge,
key crypto.Key,
destinationChainID int64) error {
input := &contractsapi.InitializeChildERC20PredicateFn{
Expand All @@ -148,7 +148,7 @@ func initExternalContracts(bridgeCfg *polybft.BridgeConfig,
name: getContractName(false, erc20TemplateName),
hasProxy: false,
artifact: contractsapi.ChildERC20,
addressPopulatorFn: func(bc *polybft.BridgeConfig, dcr []*deployContractResult) {
addressPopulatorFn: func(bc *polycfg.Bridge, dcr []*deployContractResult) {
bc.ExternalERC20Addr = dcr[0].Address
},
})
Expand All @@ -158,12 +158,12 @@ func initExternalContracts(bridgeCfg *polybft.BridgeConfig,
name: getContractName(false, erc721PredicateName),
hasProxy: true,
artifact: contractsapi.RootERC721Predicate,
addressPopulatorFn: func(bc *polybft.BridgeConfig, dcr []*deployContractResult) {
addressPopulatorFn: func(bc *polycfg.Bridge, dcr []*deployContractResult) {
bc.ExternalERC721PredicateAddr = dcr[1].Address
},
initializeFn: func(fmt command.OutputFormatter, relayer txrelayer.TxRelayer,
genesisValidators []*validator.GenesisValidator,
config *polybft.BridgeConfig,
config *polycfg.Bridge,
key crypto.Key,
destinationChainID int64) error {
input := &contractsapi.InitializeRootERC721PredicateFn{
Expand All @@ -183,12 +183,12 @@ func initExternalContracts(bridgeCfg *polybft.BridgeConfig,
name: getContractName(false, erc721MintablePredicateName),
hasProxy: true,
artifact: contractsapi.ChildERC721Predicate,
addressPopulatorFn: func(bc *polybft.BridgeConfig, dcr []*deployContractResult) {
addressPopulatorFn: func(bc *polycfg.Bridge, dcr []*deployContractResult) {
bc.ExternalMintableERC721PredicateAddr = dcr[1].Address
},
initializeFn: func(fmt command.OutputFormatter, relayer txrelayer.TxRelayer,
genesisValidators []*validator.GenesisValidator,
config *polybft.BridgeConfig,
config *polycfg.Bridge,
key crypto.Key,
destinationChainID int64) error {
input := &contractsapi.InitializeChildERC721PredicateFn{
Expand All @@ -208,7 +208,7 @@ func initExternalContracts(bridgeCfg *polybft.BridgeConfig,
name: getContractName(false, erc721TemplateName),
hasProxy: false,
artifact: contractsapi.ChildERC721,
addressPopulatorFn: func(bc *polybft.BridgeConfig, dcr []*deployContractResult) {
addressPopulatorFn: func(bc *polycfg.Bridge, dcr []*deployContractResult) {
bc.ExternalERC721Addr = dcr[0].Address
},
})
Expand All @@ -218,12 +218,12 @@ func initExternalContracts(bridgeCfg *polybft.BridgeConfig,
name: getContractName(false, erc1155PredicateName),
hasProxy: true,
artifact: contractsapi.RootERC1155Predicate,
addressPopulatorFn: func(bc *polybft.BridgeConfig, dcr []*deployContractResult) {
addressPopulatorFn: func(bc *polycfg.Bridge, dcr []*deployContractResult) {
bc.ExternalERC1155PredicateAddr = dcr[1].Address
},
initializeFn: func(fmt command.OutputFormatter, relayer txrelayer.TxRelayer,
genesisValidators []*validator.GenesisValidator,
config *polybft.BridgeConfig,
config *polycfg.Bridge,
key crypto.Key,
destinationChainID int64) error {
input := &contractsapi.InitializeRootERC1155PredicateFn{
Expand All @@ -243,12 +243,12 @@ func initExternalContracts(bridgeCfg *polybft.BridgeConfig,
name: getContractName(false, erc1155MintablePredicateName),
hasProxy: true,
artifact: contractsapi.ChildERC1155Predicate,
addressPopulatorFn: func(bc *polybft.BridgeConfig, dcr []*deployContractResult) {
addressPopulatorFn: func(bc *polycfg.Bridge, dcr []*deployContractResult) {
bc.ExternalMintableERC1155PredicateAddr = dcr[1].Address
},
initializeFn: func(fmt command.OutputFormatter, relayer txrelayer.TxRelayer,
genesisValidators []*validator.GenesisValidator,
config *polybft.BridgeConfig,
config *polycfg.Bridge,
key crypto.Key,
destinationChainID int64) error {
input := &contractsapi.InitializeChildERC1155PredicateFn{
Expand All @@ -268,7 +268,7 @@ func initExternalContracts(bridgeCfg *polybft.BridgeConfig,
name: getContractName(false, erc1155TemplateName),
hasProxy: false,
artifact: contractsapi.ChildERC1155,
addressPopulatorFn: func(bc *polybft.BridgeConfig, dcr []*deployContractResult) {
addressPopulatorFn: func(bc *polycfg.Bridge, dcr []*deployContractResult) {
bc.ExternalERC1155Addr = dcr[0].Address
},
})
Expand All @@ -280,12 +280,12 @@ func initExternalContracts(bridgeCfg *polybft.BridgeConfig,
name: bladeManagerName,
artifact: contractsapi.BladeManager,
hasProxy: true,
addressPopulatorFn: func(bc *polybft.BridgeConfig, dcr []*deployContractResult) {
addressPopulatorFn: func(bc *polycfg.Bridge, dcr []*deployContractResult) {
bc.BladeManagerAddr = dcr[1].Address
},
initializeFn: func(fmt command.OutputFormatter, relayer txrelayer.TxRelayer,
genesisValidators []*validator.GenesisValidator,
config *polybft.BridgeConfig,
config *polycfg.Bridge,
key crypto.Key,
destinationChainID int64) error {
gvs := make([]*contractsapi.GenesisAccount, len(genesisValidators))
Expand Down Expand Up @@ -316,7 +316,7 @@ func initExternalContracts(bridgeCfg *polybft.BridgeConfig,
// populateExistingNativeTokenAddr checks whether given token is deployed on the provided address.
// If it is, then its address is set to the bridge config, otherwise an error is returned
func populateExistingNativeTokenAddr(eth *jsonrpc.EthClient, tokenAddr, tokenName string,
bridgeCfg *polybft.BridgeConfig) error {
bridgeCfg *polycfg.Bridge) error {
addr := types.StringToAddress(tokenAddr)

code, err := eth.GetCode(addr, jsonrpc.LatestBlockNumberOrHash)
Expand Down
32 changes: 16 additions & 16 deletions command/bridge/deploy/internal_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/0xPolygon/polygon-edge/chain"
"github.com/0xPolygon/polygon-edge/command"
"github.com/0xPolygon/polygon-edge/consensus/polybft"
polycfg "github.com/0xPolygon/polygon-edge/consensus/polybft/config"
"github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi"
"github.com/0xPolygon/polygon-edge/consensus/polybft/validator"
"github.com/0xPolygon/polygon-edge/contracts"
Expand All @@ -30,12 +30,12 @@ func initInternalContracts(chainCfg *chain.Chain) []*contract {
name: getContractName(true, gatewayName),
hasProxy: true,
artifact: contractsapi.Gateway,
addressPopulatorFn: func(bc *polybft.BridgeConfig, dcr []*deployContractResult) {
addressPopulatorFn: func(bc *polycfg.Bridge, dcr []*deployContractResult) {
bc.InternalGatewayAddr = dcr[1].Address
},
initializeFn: func(fmt command.OutputFormatter, relayer txrelayer.TxRelayer,
genesisValidators []*validator.GenesisValidator,
config *polybft.BridgeConfig,
config *polycfg.Bridge,
key crypto.Key,
_ int64) error {
validatorSet, err := getValidatorSet(fmt, genesisValidators)
Expand Down Expand Up @@ -64,12 +64,12 @@ func initInternalContracts(chainCfg *chain.Chain) []*contract {
name: getContractName(true, erc20PredicateName),
hasProxy: true,
artifact: contractArtifact,
addressPopulatorFn: func(bc *polybft.BridgeConfig, dcr []*deployContractResult) {
addressPopulatorFn: func(bc *polycfg.Bridge, dcr []*deployContractResult) {
bc.InternalERC20PredicateAddr = dcr[1].Address
},
initializeFn: func(fmt command.OutputFormatter, relayer txrelayer.TxRelayer,
genesisValidators []*validator.GenesisValidator,
config *polybft.BridgeConfig,
config *polycfg.Bridge,
key crypto.Key,
destinationChainID int64) error {
var input contractsapi.FunctionAbi
Expand Down Expand Up @@ -109,12 +109,12 @@ func initInternalContracts(chainCfg *chain.Chain) []*contract {
name: getContractName(true, erc721PredicateName),
hasProxy: true,
artifact: contractArtifact,
addressPopulatorFn: func(bc *polybft.BridgeConfig, dcr []*deployContractResult) {
addressPopulatorFn: func(bc *polycfg.Bridge, dcr []*deployContractResult) {
bc.InternalERC721PredicateAddr = dcr[1].Address
},
initializeFn: func(fmt command.OutputFormatter, relayer txrelayer.TxRelayer,
genesisValidators []*validator.GenesisValidator,
config *polybft.BridgeConfig,
config *polycfg.Bridge,
key crypto.Key,
destinationChainID int64) error {
var input contractsapi.FunctionAbi
Expand Down Expand Up @@ -152,12 +152,12 @@ func initInternalContracts(chainCfg *chain.Chain) []*contract {
name: getContractName(true, erc1155PredicateName),
hasProxy: true,
artifact: contractArtifact,
addressPopulatorFn: func(bc *polybft.BridgeConfig, dcr []*deployContractResult) {
addressPopulatorFn: func(bc *polycfg.Bridge, dcr []*deployContractResult) {
bc.InternalERC1155PredicateAddr = dcr[1].Address
},
initializeFn: func(fmt command.OutputFormatter, relayer txrelayer.TxRelayer,
genesisValidators []*validator.GenesisValidator,
config *polybft.BridgeConfig,
config *polycfg.Bridge,
key crypto.Key,
destinationChainID int64) error {
var input contractsapi.FunctionAbi
Expand Down Expand Up @@ -195,12 +195,12 @@ func initInternalContracts(chainCfg *chain.Chain) []*contract {
name: getContractName(true, erc20MintablePredicateName),
hasProxy: true,
artifact: contractArtifact,
addressPopulatorFn: func(bc *polybft.BridgeConfig, dcr []*deployContractResult) {
addressPopulatorFn: func(bc *polycfg.Bridge, dcr []*deployContractResult) {
bc.InternalMintableERC20PredicateAddr = dcr[1].Address
},
initializeFn: func(fmt command.OutputFormatter, relayer txrelayer.TxRelayer,
genesisValidators []*validator.GenesisValidator,
config *polybft.BridgeConfig,
config *polycfg.Bridge,
key crypto.Key,
destinationChainID int64) error {
var input contractsapi.FunctionAbi
Expand Down Expand Up @@ -238,12 +238,12 @@ func initInternalContracts(chainCfg *chain.Chain) []*contract {
name: getContractName(true, erc721MintablePredicateName),
hasProxy: true,
artifact: contractArtifact,
addressPopulatorFn: func(bc *polybft.BridgeConfig, dcr []*deployContractResult) {
addressPopulatorFn: func(bc *polycfg.Bridge, dcr []*deployContractResult) {
bc.InternalMintableERC721PredicateAddr = dcr[1].Address
},
initializeFn: func(fmt command.OutputFormatter, relayer txrelayer.TxRelayer,
genesisValidators []*validator.GenesisValidator,
config *polybft.BridgeConfig,
config *polycfg.Bridge,
key crypto.Key,
destinationChainID int64) error {
var input contractsapi.FunctionAbi
Expand Down Expand Up @@ -281,12 +281,12 @@ func initInternalContracts(chainCfg *chain.Chain) []*contract {
name: getContractName(true, erc1155MintablePredicateName),
hasProxy: true,
artifact: contractArtifact,
addressPopulatorFn: func(bc *polybft.BridgeConfig, dcr []*deployContractResult) {
addressPopulatorFn: func(bc *polycfg.Bridge, dcr []*deployContractResult) {
bc.InternalMintableERC1155PredicateAddr = dcr[1].Address
},
initializeFn: func(fmt command.OutputFormatter, relayer txrelayer.TxRelayer,
genesisValidators []*validator.GenesisValidator,
config *polybft.BridgeConfig,
config *polycfg.Bridge,
key crypto.Key,
destinationChainID int64) error {
var input contractsapi.FunctionAbi
Expand Down Expand Up @@ -320,7 +320,7 @@ func initInternalContracts(chainCfg *chain.Chain) []*contract {
// preAllocateInternalPredicates pre-allocates internal predicates in genesis
// if the command is run in bootstrap mode
func preAllocateInternalPredicates(o command.OutputFormatter, internalContracts []*contract,
chainCfg *chain.Chain, bridgeCfg *polybft.BridgeConfig) error {
chainCfg *chain.Chain, bridgeCfg *polycfg.Bridge) error {
predicateBaseProxyAddress := contracts.ChildBridgeContractsBaseAddress

if consensusCfg.Bridge != nil {
Expand Down
Loading
Loading