-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a devnet docker image for local development. It uses rollups-contracts own deployment scripts instead of foundry-rs and replaces the shell script previousaly developed for the same purpose.
- Loading branch information
1 parent
5bd4be4
commit d1ccc10
Showing
15 changed files
with
475 additions
and
653 deletions.
There are no files selected for viewing
This file contains 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 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 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,30 @@ | ||
// (c) Cartesi and individual authors (see AUTHORS) | ||
// SPDX-License-Identifier: Apache-2.0 (see LICENSE) | ||
|
||
package main | ||
|
||
import ( | ||
"os" | ||
"strconv" | ||
|
||
"github.com/cartesi/rollups-node/internal/services" | ||
) | ||
|
||
const ANVIL_STATE_INTERVAL int = 1 | ||
|
||
func newAnvilService(depConfig DeploymentConfig) services.CommandService { | ||
var s services.CommandService | ||
s.Name = "anvil" | ||
s.HealthcheckPort = 8545 | ||
s.Path = "anvil" | ||
|
||
s.Args = append(s.Args, "--host", depConfig.AnvilIpAddr) | ||
s.Args = append(s.Args, "--dump-state", depConfig.AnvilStateFilePath) | ||
s.Args = append(s.Args, "--state-interval", strconv.Itoa(ANVIL_STATE_INTERVAL)) | ||
s.Args = append(s.Args, "--silent") | ||
|
||
s.Env = append(s.Env, "ANVIL_IP_ADDR=0.0.0.0") | ||
s.Env = append(s.Env, os.Environ()...) | ||
|
||
return s | ||
} |
This file contains 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,130 @@ | ||
// (c) Cartesi and individual authors (see AUTHORS) | ||
// SPDX-License-Identifier: Apache-2.0 (see LICENSE) | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"os/exec" | ||
"strings" | ||
|
||
"github.com/cartesi/rollups-node/internal/config" | ||
) | ||
|
||
func deploy(ctx context.Context, | ||
depConfig DeploymentConfig) (DeploymentInfo, error) { | ||
var depInfo DeploymentInfo | ||
|
||
config.InfoLogger.Printf("deployer: deploying %s", depConfig.RollupsContractsPath) | ||
err := deployRollupsContracts(ctx, depConfig) | ||
if err != nil { | ||
return depInfo, fmt.Errorf("could not deploy rollups-contracts: %v", err) | ||
} | ||
|
||
config.InfoLogger.Println("deployer: creating application...") | ||
depInfo, err = createApplication(ctx, depConfig) | ||
if err != nil { | ||
return depInfo, fmt.Errorf("could not create Application: %v", err) | ||
} | ||
|
||
config.InfoLogger.Println("deployer: gathering application info...") | ||
return depInfo, nil | ||
} | ||
|
||
// Create a Rollups Application by calling the necessary factories | ||
func createApplication(ctx context.Context, depConfig DeploymentConfig) (DeploymentInfo, error) { | ||
var depInfo DeploymentInfo | ||
if depConfig.Hash == "" { | ||
return DeploymentInfo{}, fmt.Errorf("machine hash is missing") | ||
} | ||
|
||
// Create the Authority/History pair | ||
addresses, _, err := execContract(ctx, | ||
depConfig, | ||
depConfig.AuthorityHistoryFactoryAddress, | ||
"newAuthorityHistoryPair(address,bytes32)(address,address)", | ||
depConfig.SignerAddress, | ||
depConfig.Salt) | ||
if err != nil { | ||
return DeploymentInfo{}, fmt.Errorf("could not create authority/history pair: %v", err) | ||
} | ||
|
||
depInfo.AuthorityAddress = addresses[0] | ||
depInfo.HistoryAddress = addresses[1] | ||
|
||
// Create the Application, passing the address of the newly created Authority | ||
addresses, blockNumber, err := execContract(ctx, | ||
depConfig, | ||
depConfig.ApplicationFactoryAddress, | ||
"newApplication(address,address,bytes32,bytes32)(address)", | ||
depInfo.AuthorityAddress, | ||
depConfig.SignerAddress, | ||
depConfig.Hash, | ||
depConfig.Salt) | ||
if err != nil { | ||
return DeploymentInfo{}, fmt.Errorf("could not create application: %v", err) | ||
} | ||
|
||
depInfo.ApplicationAddress = addresses[0] | ||
depInfo.BlockNumber = blockNumber | ||
|
||
return depInfo, nil | ||
} | ||
|
||
// Call a contract factory, passing a factory function to be executed. | ||
// Returns the resulting contract address(es) and the corresponding | ||
// block number. | ||
// | ||
// Warning: a second call to a contract with the same arguments will fail. | ||
func execContract(ctx context.Context, | ||
depConfig DeploymentConfig, | ||
args ...string) ([]string, string, error) { | ||
rpcUrl := "http://" + depConfig.AnvilIpAddr + ":" + depConfig.AnvilPort | ||
commonArgs := []string{"--rpc-url", rpcUrl} | ||
commonArgs = append(commonArgs, args...) | ||
|
||
var addresses []string | ||
// Calculate the resulting deterministic address(es) | ||
castCall := exec.CommandContext(ctx, | ||
"cast", | ||
"call") | ||
castCall.Args = append(castCall.Args, commonArgs...) | ||
var outStrBuilder strings.Builder | ||
castCall.Stdout = &outStrBuilder | ||
err := castCall.Run() | ||
if err != nil { | ||
return addresses, "", fmt.Errorf("command failed %v: %v", castCall.Args, err) | ||
} | ||
addresses = strings.Fields(outStrBuilder.String()) | ||
|
||
// Perform actual transaction on the contract | ||
castSend := exec.CommandContext(ctx, | ||
"cast", | ||
"send", | ||
"--json", | ||
"--mnemonic", | ||
depConfig.Mnemonic) | ||
castSend.Args = append(castSend.Args, commonArgs...) | ||
outStrBuilder.Reset() | ||
castSend.Stdout = &outStrBuilder | ||
err = castSend.Run() | ||
if err != nil { | ||
return addresses, "", fmt.Errorf("command failed %v: %v", castSend.Args, err) | ||
} | ||
if !depConfig.IsSilent { | ||
config.InfoLogger.Printf("deployer: executed command %s", castSend.Args) | ||
config.InfoLogger.Printf("deployer: output: %s", outStrBuilder.String()) | ||
} | ||
|
||
// Extract blockNumber from JSON output | ||
jsonMap := make(map[string](any)) | ||
err = json.Unmarshal([]byte([]byte(outStrBuilder.String())), &jsonMap) | ||
if err != nil { | ||
return addresses, "", fmt.Errorf("failed to extract block number, %s", err.Error()) | ||
} | ||
blockNumber := jsonMap["blockNumber"].(string) | ||
|
||
return addresses, blockNumber, nil | ||
} |
Oops, something went wrong.