Skip to content

Commit

Permalink
Fetch latest SC changes and update checkpoint manager deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan-Ethernal committed Sep 26, 2023
1 parent cfc0ada commit f06b1de
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 22 deletions.
29 changes: 25 additions & 4 deletions command/rootchain/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,10 @@ func deployContracts(outputter command.OutputFormatter, client *jsonrpc.Client,
}

type contractInfo struct {
name string
artifact *artifact.Artifact
hasProxy bool
name string
artifact *artifact.Artifact
hasProxy bool
byteCodeBuilder func() ([]byte, error)
}

rootchainConfig := &polybft.RootchainConfig{
Expand Down Expand Up @@ -469,6 +470,18 @@ func deployContracts(outputter command.OutputFormatter, client *jsonrpc.Client,
name: checkpointManagerName,
artifact: contractsapi.CheckpointManager,
hasProxy: true,
byteCodeBuilder: func() ([]byte, error) {
constructorFn := &contractsapi.CheckpointManagerConstructorFn{
Initiator: types.Address(deployerKey.Address()),
}

input, err := constructorFn.EncodeAbi()
if err != nil {
return nil, err
}

return append(contractsapi.CheckpointManager.Bytecode, input...), nil
},
},
{
name: blsName,
Expand Down Expand Up @@ -549,7 +562,15 @@ func deployContracts(outputter command.OutputFormatter, client *jsonrpc.Client,
case <-ctx.Done():
return ctx.Err()
default:
txn := helper.CreateTransaction(ethgo.ZeroAddress, nil, contract.artifact.Bytecode, nil, true)
bytecode := contract.artifact.Bytecode
if contract.byteCodeBuilder != nil {
bytecode, err = contract.byteCodeBuilder()
if err != nil {
return err
}
}

txn := helper.CreateTransaction(ethgo.ZeroAddress, nil, bytecode, nil, true)

receipt, err := txRelayer.SendTransaction(txn, deployerKey)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion consensus/polybft/contractsapi/bindings-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func main() {
{
"CheckpointManager",
gensc.CheckpointManager,
false,
true,
[]string{
"submit",
"initialize",
Expand Down
26 changes: 20 additions & 6 deletions consensus/polybft/contractsapi/contractsapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions consensus/polybft/contractsapi/gen_sc_data.go

Large diffs are not rendered by default.

20 changes: 12 additions & 8 deletions consensus/polybft/sc_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/0xPolygon/polygon-edge/chain"
"github.com/0xPolygon/polygon-edge/consensus/polybft/bitmap"
"github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi"
"github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi/artifact"
bls "github.com/0xPolygon/polygon-edge/consensus/polybft/signer"
"github.com/0xPolygon/polygon-edge/consensus/polybft/validator"
"github.com/0xPolygon/polygon-edge/contracts"
Expand All @@ -24,7 +23,7 @@ import (
"github.com/0xPolygon/polygon-edge/types"
)

func TestIntegratoin_PerformExit(t *testing.T) {
func TestIntegration_PerformExit(t *testing.T) {
t.Parallel()

const gasLimit = 1000000000000
Expand Down Expand Up @@ -62,7 +61,7 @@ func TestIntegratoin_PerformExit(t *testing.T) {
}

// deploy MockERC20 as root chain ERC 20 token
rootERC20Addr := deployAndInitContract(t, transition, contractsapi.RootERC20, deployerAddress, nil)
rootERC20Addr := deployAndInitContract(t, transition, contractsapi.RootERC20.Bytecode, deployerAddress, nil)

// deploy CheckpointManager
checkpointManagerInit := func() ([]byte, error) {
Expand All @@ -73,13 +72,18 @@ func TestIntegratoin_PerformExit(t *testing.T) {
ChainID_: big.NewInt(0),
}).EncodeAbi()
}
checkpointManagerAddr := deployAndInitContract(t, transition, contractsapi.CheckpointManager, deployerAddress, checkpointManagerInit)

checkpointMgrConstructor := &contractsapi.CheckpointManagerConstructorFn{Initiator: deployerAddress}
constructorInput, err := checkpointMgrConstructor.EncodeAbi()
require.NoError(t, err)

checkpointManagerAddr := deployAndInitContract(t, transition, append(contractsapi.CheckpointManager.Bytecode, constructorInput...), deployerAddress, checkpointManagerInit)

// deploy ExitHelper
exitHelperInit := func() ([]byte, error) {
return (&contractsapi.InitializeExitHelperFn{NewCheckpointManager: checkpointManagerAddr}).EncodeAbi()
}
exitHelperContractAddress := deployAndInitContract(t, transition, contractsapi.ExitHelper, deployerAddress, exitHelperInit)
exitHelperContractAddress := deployAndInitContract(t, transition, contractsapi.ExitHelper.Bytecode, deployerAddress, exitHelperInit)

// deploy RootERC20Predicate
rootERC20PredicateInit := func() ([]byte, error) {
Expand All @@ -91,7 +95,7 @@ func TestIntegratoin_PerformExit(t *testing.T) {
NativeTokenRootAddress: contracts.NativeERC20TokenContract,
}).EncodeAbi()
}
rootERC20PredicateAddr := deployAndInitContract(t, transition, contractsapi.RootERC20Predicate, deployerAddress, rootERC20PredicateInit)
rootERC20PredicateAddr := deployAndInitContract(t, transition, contractsapi.RootERC20Predicate.Bytecode, deployerAddress, rootERC20PredicateInit)

// validate initialization of CheckpointManager
require.Equal(t, getField(checkpointManagerAddr, contractsapi.CheckpointManager.Abi, "currentCheckpointBlockNumber")[31], uint8(0))
Expand Down Expand Up @@ -390,11 +394,11 @@ func TestIntegration_CommitEpoch(t *testing.T) {
}
}

func deployAndInitContract(t *testing.T, transition *state.Transition, scArtifact *artifact.Artifact, sender types.Address,
func deployAndInitContract(t *testing.T, transition *state.Transition, bytecode []byte, sender types.Address,
initCallback func() ([]byte, error)) types.Address {
t.Helper()

deployResult := transition.Create2(sender, scArtifact.Bytecode, big.NewInt(0), 1e9)
deployResult := transition.Create2(sender, bytecode, big.NewInt(0), 1e9)
assert.NoError(t, deployResult.Err)

if initCallback != nil {
Expand Down
2 changes: 1 addition & 1 deletion core-contracts

0 comments on commit f06b1de

Please sign in to comment.