-
Notifications
You must be signed in to change notification settings - Fork 8
Feature/setup dac #4
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
Open
arnaubennassar
wants to merge
17
commits into
main
Choose a base branch
from
feature/setup-dac
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+5,754
−70
Open
Changes from 7 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
db538d6
WIP
arnaubennassar 224e298
WIP
arnaubennassar 664d060
WIP
arnaubennassar 59ce7da
WIP
arnaubennassar a48147a
WIP
arnaubennassar 11e9e69
WIP
arnaubennassar 7f18da0
Add docker support
arnaubennassar cd2bd8f
WIP
arnaubennassar 49a69ba
Fix test after refactor
arnaubennassar 2c61dd4
WIP
arnaubennassar d150875
Rollup Manager deplyment completed and tested
arnaubennassar 8497189
Add rollup manager into networks after deploying
arnaubennassar f0df113
Pass test
arnaubennassar b09e501
Add instructions to generate docker image
arnaubennassar 39190c3
Add missing commands to make test work
arnaubennassar 1fda710
Merge pull request #7 from 0xPolygon/feature/rollupman-ops
arnaubennassar dcedb84
Merge pull request #6 from 0xPolygon/feature/deploy-rollup-manager
arnaubennassar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,3 +22,7 @@ wallets.toml | |
|
|
||
| # Go workspace file | ||
| go.work | ||
| docker/gethData | ||
|
|
||
| # Node | ||
| node_modules | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"address":"f39fd6e51aad88f6f4ce6ab8827279cfffb92266","crypto":{"cipher":"aes-128-ctr","ciphertext":"d005030a7684f3adad2447cbb27f63039eec2224c451eaa445de0d90502b9f3d","cipherparams":{"iv":"dc07a54bc7e388efa89c34d42f2ebdb4"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"cf2ec55ecae11171de575112cfb16963570533a9c46fb774473ceb11519eb24a"},"mac":"3eb180d405a5da6e462b2adc00091c14856c91d574bf27348714506357d6e177"},"id":"035454db-6b6d-477f-8a79-ce24c10b185f","version":3} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
| "path" | ||
| "testing" | ||
|
|
||
| "github.com/0xPolygon/cdk-contracts-tooling/docker" | ||
| "github.com/ethereum/go-ethereum/ethclient" | ||
| ) | ||
|
|
||
| const ( | ||
| thisDir = "cmd" | ||
| walletAddr = "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266" | ||
| walletPass = "testonly" | ||
| ) | ||
|
|
||
| func TestMain(t *testing.M) { | ||
| baseDir, err := os.Getwd() | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| _, f := path.Split(baseDir) | ||
| if f == thisDir { | ||
| err = os.Chdir("..") | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| } | ||
| ctx := context.Background() | ||
| if err := docker.StartMockL1Docker(ctx); err != nil { | ||
| panic(err) | ||
| } | ||
| defer func() { | ||
| if err := docker.StopMockL1Docker(); err != nil { | ||
| panic(err) | ||
| } | ||
| }() | ||
| t.Run() | ||
| } | ||
|
|
||
| func getClient() (*ethclient.Client, error) { | ||
| return ethclient.Dial("http://localhost:8545") | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,214 @@ | ||||||
| package main | ||||||
|
|
||||||
| import ( | ||||||
| "encoding/json" | ||||||
| "errors" | ||||||
| "fmt" | ||||||
| "math/big" | ||||||
| "os" | ||||||
| "sort" | ||||||
| "strings" | ||||||
|
|
||||||
| "github.com/0xPolygon/cdk-contracts-tooling/contracts/common/erc1967proxy" | ||||||
| "github.com/0xPolygon/cdk-contracts-tooling/contracts/elderberry/polygondatacommittee" | ||||||
| "github.com/ethereum/go-ethereum/common" | ||||||
| "github.com/ethereum/go-ethereum/core/types" | ||||||
| "github.com/urfave/cli/v2" | ||||||
| ) | ||||||
|
|
||||||
| const ( | ||||||
| setupDACFilePathFlagName = "setup-file" | ||||||
| implementationAddressFlagName = "implementation-address" | ||||||
| ) | ||||||
|
|
||||||
| var ( | ||||||
| deployDACCommand = &cli.Command{ | ||||||
| Name: "deploy-dac", | ||||||
| Aliases: []string{}, | ||||||
| Usage: "Deploy the Data Availability smart contract", | ||||||
| Action: deployDAC, | ||||||
| Flags: []cli.Flag{ | ||||||
| l1Flag, | ||||||
| walletFlag, | ||||||
| walletPasswordFlag, | ||||||
| skipConfirmationFlag, | ||||||
| timeoutFlag, | ||||||
| &cli.StringFlag{ | ||||||
| Name: implementationAddressFlagName, | ||||||
| Aliases: []string{"implementation", "impl"}, | ||||||
| Usage: `Smart contract address of a DAC implementation. If provided, it will be used for the proxy implementation instead of deploying a new one`, | ||||||
| Required: false, | ||||||
| }, | ||||||
| }, | ||||||
| } | ||||||
| setupDACCommand = &cli.Command{ | ||||||
| Name: "setup-dac", | ||||||
| Aliases: []string{}, | ||||||
| Usage: "Setup a Data Availability smart contract", | ||||||
| Action: setupDAC, | ||||||
| Flags: []cli.Flag{ | ||||||
| l1Flag, | ||||||
| addressFlag, | ||||||
| walletFlag, | ||||||
| walletPasswordFlag, | ||||||
| skipConfirmationFlag, | ||||||
| timeoutFlag, | ||||||
| &cli.PathFlag{ | ||||||
| Name: setupDACFilePathFlagName, | ||||||
| Aliases: []string{"f"}, | ||||||
| Usage: `File path of a JSON that looks like {"requiredSingatures": X, "members": [{"address": "0x...", "url": "http://..."}]}`, | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Probably it would be a good idea providing a JSON example as it is done for the wallets and rpcs toml files? |
||||||
| Required: true, | ||||||
| }, | ||||||
| }, | ||||||
| } | ||||||
| ) | ||||||
|
|
||||||
| func deployDAC(cliCtx *cli.Context) error { | ||||||
| _, err := checkWorkingDir() | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
| walletAddr, auth, client, err := loadAuthAndClient(cliCtx) | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
|
|
||||||
| timeout := getTimeout(cliCtx) | ||||||
| dacAddrStr := cliCtx.String(implementationAddressFlagName) | ||||||
| var dacAddr common.Address | ||||||
| if dacAddrStr != "" { | ||||||
| dacAddr = common.HexToAddress(dacAddrStr) | ||||||
| fmt.Printf("Using %s as DAC implementation (previously deployed)\n", dacAddr) | ||||||
| } else { | ||||||
| err = askForConfirmation(cliCtx, fmt.Sprintf( | ||||||
| "Do you want to send the tx that will deploy the DAC from the address %s?", | ||||||
| walletAddr, | ||||||
| )) | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
| fmt.Println("deploying DAC implementaiton") | ||||||
| var tx *types.Transaction | ||||||
| dacAddr, tx, _, err = polygondatacommittee.DeployPolygondatacommittee(auth, client) | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
| fmt.Printf("DAC implementation will be deployed at %s with the tx %s\n", dacAddr.Hex(), tx.Hash()) | ||||||
| fmt.Printf("Waiting for the tx to be mined, this will timeout after %s\n", timeout) | ||||||
| ok, err := waitTxToBeMined(cliCtx.Context, client, tx, timeout) | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
| if !ok { | ||||||
| return errors.New("the transaction was mined, but it was not executed successfuly") | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| fmt.Println("deploying proxy") | ||||||
| proxyAddr, tx, _, err := erc1967proxy.DeployErc1967proxy( | ||||||
| auth, | ||||||
| client, | ||||||
| dacAddr, | ||||||
| common.Hex2Bytes("8129fc1c00000000000000000000000000000000000000000000000000000000"), // initialize() signature | ||||||
| ) | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
| fmt.Printf("DAC proxy will be deployed at %s with the tx %s\n", proxyAddr.Hex(), tx.Hash()) | ||||||
| fmt.Printf("Waiting for the tx to be mined, this will timeout after %s\n", timeout) | ||||||
| ok, err := waitTxToBeMined(cliCtx.Context, client, tx, timeout) | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
| if !ok { | ||||||
| return errors.New("the transaction was mined, but it was not executed successfuly") | ||||||
| } | ||||||
|
|
||||||
| return nil | ||||||
| } | ||||||
|
|
||||||
| func setupDAC(cliCtx *cli.Context) error { | ||||||
| _, err := checkWorkingDir() | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
| walletAddr, auth, client, err := loadAuthAndClient(cliCtx) | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
|
|
||||||
| fmt.Println("loading setup file") | ||||||
| setupDACFilePath := cliCtx.String(setupDACFilePathFlagName) | ||||||
| data, err := os.ReadFile(setupDACFilePath) | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
| var setup DACSetup | ||||||
| err = json.Unmarshal(data, &setup) | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
| fmt.Printf(` | ||||||
| DAC Configuration: | ||||||
| required signatures %d / %d. | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| Members: %+v | ||||||
|
|
||||||
| `, setup.RequiredSingatures, len(setup.Members), setup.Members, | ||||||
| ) | ||||||
| dacAddr := cliCtx.String(addressFlagName) | ||||||
| err = askForConfirmation(cliCtx, fmt.Sprintf( | ||||||
| "Do you want to send the tx that will setup the DAC deployed at %s from the address %s with the configuration shown above?", | ||||||
| dacAddr, walletAddr, | ||||||
| )) | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
|
|
||||||
| fmt.Println("sending tx") | ||||||
| dac, err := polygondatacommittee.NewPolygondatacommittee(common.HexToAddress(dacAddr), client) | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
| addrs, urls := setup.MembersAndAddrsForSetup() | ||||||
| tx, err := dac.SetupCommittee(auth, big.NewInt(setup.RequiredSingatures), urls, addrs) | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
| fmt.Printf("DAC will be setup with the tx %s\n", tx.Hash()) | ||||||
| timeout := getTimeout(cliCtx) | ||||||
| fmt.Printf("Waiting for the tx to be mined, this will timeout after %s\n", timeout) | ||||||
| ok, err := waitTxToBeMined(cliCtx.Context, client, tx, timeout) | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
| if !ok { | ||||||
| return errors.New("the transaction was mined, but it was not executed successfuly") | ||||||
| } | ||||||
|
|
||||||
| return nil | ||||||
| } | ||||||
|
|
||||||
| type DACMember struct { | ||||||
| Address common.Address `json:"address"` | ||||||
| URL string `json:"url"` | ||||||
| } | ||||||
|
|
||||||
| type DACSetup struct { | ||||||
| RequiredSingatures int64 `json:"requiredSingatures"` | ||||||
| Members []DACMember `json:"members"` | ||||||
| } | ||||||
|
|
||||||
| func (s DACSetup) Len() int { return len(s.Members) } | ||||||
| func (s DACSetup) Less(i, j int) bool { | ||||||
| return strings.ToUpper(s.Members[i].Address.Hex()) < strings.ToUpper(s.Members[j].Address.Hex()) | ||||||
| } | ||||||
| func (s DACSetup) Swap(i, j int) { s.Members[i], s.Members[j] = s.Members[j], s.Members[i] } | ||||||
|
|
||||||
| func (d *DACSetup) MembersAndAddrsForSetup() (addrsBytes []byte, urls []string) { | ||||||
| sort.Sort(d) | ||||||
| for _, m := range d.Members { | ||||||
| addrsBytes = append(addrsBytes, m.Address.Bytes()...) | ||||||
| urls = append(urls, m.URL) | ||||||
| } | ||||||
| return | ||||||
| } | ||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably doesn't deserve a separate function for this. WDYT?
Also as a side note, would it be an overkill if we were starting up the mock l1 network in case it is not running already?