Skip to content

Commit

Permalink
fix: todo
Browse files Browse the repository at this point in the history
  • Loading branch information
renan061 committed Jul 5, 2024
1 parent f284e89 commit 9ed81ad
Show file tree
Hide file tree
Showing 19 changed files with 141 additions and 135 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Changed the dispatcher to close epochs based on block numbers instead of block timestamps.
- **BREAKING**: replaced the environment variable `CARTESI_EPOCH_DURATION` with `CARTESI_EPOCH_LENGTH_IN_BLOCKS` to match the new epoch algorithm, and set its default value to 7200 (1 day worth of blocks, in average, considering one block is mined every 12 seconds).
- **BREAKING**: replaced the internal environment variable `RD_EPOCH_DURATION` with `RD_EPOCH_LENGTH_IN_BLOCKS` to match the new epoch algorithm, and also set its default value to 7200.
- **BREAKING**: changed the dispatcher to use the `CARTESI_CONTRACTS_INPUT_BOX_DEPLOYMENT_BLOCK_NUMBER` environment variable instead of `CARTESI_CONTRACTS_APPLICATION_DEPLOYMENT_BLOCK_NUMBER`.
- **BREAKING**: replaced the environment variable `CARTESI_EPOCH_DURATION` with `CARTESI_EPOCH_LENGTH` to match the new epoch algorithm, and set its default value to 7200 (1 day worth of blocks, in average, considering one block is mined every 12 seconds).
- **BREAKING**: replaced the internal environment variable `RD_EPOCH_DURATION` with `RD_EPOCH_LENGTH` to match the new epoch algorithm, and also set its default value to 7200.
- Bumped Rust Version to 1.78.0

### Removed

- Removed `CARTESI_CONTRACTS_APPLICATION_DEPLOYMENT_BLOCK_NUMBER` environment variable.

## [1.4.0] 2024-04-09

### Added
Expand Down
1 change: 0 additions & 1 deletion build/compose-devnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ services:
CARTESI_BLOCKCHAIN_IS_LEGACY: "false"
CARTESI_BLOCKCHAIN_FINALITY_OFFSET: "1"
CARTESI_CONTRACTS_APPLICATION_ADDRESS: "0x7C54E3f7A8070a54223469965A871fB8f6f88c22"
CARTESI_CONTRACTS_APPLICATION_DEPLOYMENT_BLOCK_NUMBER: "20"
CARTESI_CONTRACTS_HISTORY_ADDRESS: "0x325272217ae6815b494bF38cED004c5Eb8a7CdA7"
CARTESI_CONTRACTS_AUTHORITY_ADDRESS: "0x58c93F83fb3304730C95aad2E360cdb88b782010"
CARTESI_CONTRACTS_INPUT_BOX_ADDRESS: "0x59b22D57D4f067708AB0c00552767405926dc768"
Expand Down
1 change: 0 additions & 1 deletion build/compose-sepolia.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ services:
CARTESI_BLOCKCHAIN_IS_LEGACY: "false"
CARTESI_BLOCKCHAIN_FINALITY_OFFSET: "1"
CARTESI_CONTRACTS_APPLICATION_ADDRESS: "0x9f12D4365806FC000D6555ACB85c5371b464E506"
CARTESI_CONTRACTS_APPLICATION_DEPLOYMENT_BLOCK_NUMBER: "4152308"
CARTESI_CONTRACTS_HISTORY_ADDRESS: "0x76f4dCaC0920826541EE718214EEE4be07346cEE"
CARTESI_CONTRACTS_AUTHORITY_ADDRESS: "0x5827Ec9365D3a9b27bF1dB982d258Ad234D37242"
CARTESI_CONTRACTS_INPUT_BOX_ADDRESS: "0x59b22D57D4f067708AB0c00552767405926dc768"
Expand Down
21 changes: 6 additions & 15 deletions cmd/gen-devnet/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package main

import (
"context"
"encoding/json"
"fmt"
"os/exec"
"strings"
Expand Down Expand Up @@ -44,7 +43,7 @@ func createApplication(ctx context.Context, hash string) (DeploymentInfo, error)
var depInfo DeploymentInfo

// Create the Authority/History pair
contractAddresses, _, err := createContracts(ctx,
contractAddresses, err := createContracts(ctx,
common.Address.Hex(addresses.GetTestBook().AuthorityHistoryPairFactory),
"newAuthorityHistoryPair(address,bytes32)(address,address)",
CONTRACT_OWNER_ADDRESS,
Expand All @@ -57,7 +56,7 @@ func createApplication(ctx context.Context, hash string) (DeploymentInfo, error)
depInfo.HistoryAddress = contractAddresses[1]

// Create the Application, passing the address of the newly created Authority
contractAddresses, blockNumber, err := createContracts(ctx,
contractAddresses, err = createContracts(ctx,
common.Address.Hex(addresses.GetTestBook().CartesiDAppFactory),
"newApplication(address,address,bytes32,bytes32)(address)",
depInfo.AuthorityAddress,
Expand All @@ -69,7 +68,6 @@ func createApplication(ctx context.Context, hash string) (DeploymentInfo, error)
}

depInfo.ApplicationAddress = contractAddresses[0]
depInfo.BlockNumber = blockNumber

return depInfo, nil
}
Expand All @@ -80,7 +78,7 @@ func createApplication(ctx context.Context, hash string) (DeploymentInfo, error)
//
// Warning: a second call to a contract with the same arguments will fail.
func createContracts(ctx context.Context,
args ...string) ([]string, string, error) {
args ...string) ([]string, error) {
commonArgs := []string{"--rpc-url", RPC_URL}
commonArgs = append(commonArgs, args...)

Expand All @@ -94,7 +92,7 @@ func createContracts(ctx context.Context,
castCall.Stdout = &outStrBuilder
err := castCall.Run()
if err != nil {
return contractAddresses, "", fmt.Errorf("command failed %v: %v", castCall.Args, err)
return contractAddresses, fmt.Errorf("command failed %v: %v", castCall.Args, err)
}
contractAddresses = strings.Fields(outStrBuilder.String())

Expand All @@ -110,20 +108,13 @@ func createContracts(ctx context.Context,
castSend.Stdout = &outStrBuilder
err = castSend.Run()
if err != nil {
return contractAddresses, "", fmt.Errorf("command failed %v: %v", castSend.Args, err)
return contractAddresses, fmt.Errorf("command failed %v: %v", castSend.Args, err)
}

if VerboseLog {
fmt.Printf("deployer: command: %s\n", castSend.Args)
fmt.Printf("deployer: output: %s\n", outStrBuilder.String())
}
// Extract blockNumber from JSON output
jsonMap := make(map[string](any))
err = json.Unmarshal([]byte([]byte(outStrBuilder.String())), &jsonMap)
if err != nil {
return contractAddresses, "", fmt.Errorf("failed to extract block number, %s", err.Error())
}
blockNumber := jsonMap["blockNumber"].(string)

return contractAddresses, blockNumber, nil
return contractAddresses, nil
}
1 change: 0 additions & 1 deletion cmd/gen-devnet/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ type DeploymentInfo struct {
AuthorityAddress string `json:"CARTESI_CONTRACTS_AUTHORITY_ADDRESS"`
HistoryAddress string `json:"CARTESI_CONTRACTS_HISTORY_ADDRESS"`
ApplicationAddress string `json:"CARTESI_CONTRACTS_APPLICATION_ADDRESS"`
BlockNumber string `json:"CARTESI_CONTRACTS_APPLICATION_DEPLOYMENT_BLOCK_NUMBER"`
}
8 changes: 1 addition & 7 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,6 @@ Address of the DApp's contract.

* **Type:** `string`

## `CARTESI_CONTRACTS_APPLICATION_DEPLOYMENT_BLOCK_NUMBER`

Block in which the DApp's contract was deployed.

* **Type:** `int64`

## `CARTESI_CONTRACTS_AUTHORITY_ADDRESS`

Address of the Authority contract.
Expand Down Expand Up @@ -236,7 +230,7 @@ for more information.
* **Type:** `string`
* **Default:** `""`

## `CARTESI_EPOCH_LENGTH_IN_BLOCKS`
## `CARTESI_EPOCH_LENGTH`

Length of a rollups epoch in blocks.

Expand Down
55 changes: 26 additions & 29 deletions internal/node/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,31 @@ import (
// NodeConfig contains all the Node variables.
// See the corresponding environment variable for the variable documentation.
type NodeConfig struct {
LogLevel LogLevel
LogPretty bool
RollupsEpochLengthInBlocks uint64
BlockchainID uint64
BlockchainHttpEndpoint Redacted[string]
BlockchainWsEndpoint Redacted[string]
BlockchainIsLegacy bool
BlockchainFinalityOffset int
BlockchainBlockTimeout int
ContractsApplicationAddress string
ContractsApplicationDeploymentBlockNumber int64
ContractsHistoryAddress string
ContractsAuthorityAddress string
ContractsInputBoxAddress string
ContractsInputBoxDeploymentBlockNumber int64
SnapshotDir string
PostgresEndpoint Redacted[string]
HttpAddress string
HttpPort int
FeatureHostMode bool
FeatureDisableClaimer bool
FeatureDisableMachineHashCheck bool
ExperimentalServerManagerBypassLog bool
ExperimentalSunodoValidatorEnabled bool
ExperimentalSunodoValidatorRedisEndpoint string
Auth Auth
LogLevel LogLevel
LogPretty bool
RollupsEpochLength uint64
BlockchainID uint64
BlockchainHttpEndpoint Redacted[string]
BlockchainWsEndpoint Redacted[string]
BlockchainIsLegacy bool
BlockchainFinalityOffset int
BlockchainBlockTimeout int
ContractsApplicationAddress string
ContractsHistoryAddress string
ContractsAuthorityAddress string
ContractsInputBoxAddress string
ContractsInputBoxDeploymentBlockNumber int64
SnapshotDir string
PostgresEndpoint Redacted[string]
HttpAddress string
HttpPort int
FeatureHostMode bool
FeatureDisableClaimer bool
FeatureDisableMachineHashCheck bool
ExperimentalServerManagerBypassLog bool
ExperimentalSunodoValidatorEnabled bool
ExperimentalSunodoValidatorRedisEndpoint string
Auth Auth
}

// Auth is used to sign transactions.
Expand Down Expand Up @@ -75,16 +74,14 @@ func FromEnv() NodeConfig {
var config NodeConfig
config.LogLevel = getLogLevel()
config.LogPretty = getLogPretty()
config.RollupsEpochLengthInBlocks = getEpochLengthInBlocks()
config.RollupsEpochLength = getEpochLength()
config.BlockchainID = getBlockchainId()
config.BlockchainHttpEndpoint = Redacted[string]{getBlockchainHttpEndpoint()}
config.BlockchainWsEndpoint = Redacted[string]{getBlockchainWsEndpoint()}
config.BlockchainIsLegacy = getBlockchainIsLegacy()
config.BlockchainFinalityOffset = getBlockchainFinalityOffset()
config.BlockchainBlockTimeout = getBlockchainBlockTimeout()
config.ContractsApplicationAddress = getContractsApplicationAddress()
config.ContractsApplicationDeploymentBlockNumber =
getContractsApplicationDeploymentBlockNumber()
config.ContractsHistoryAddress = getContractsHistoryAddress()
config.ContractsAuthorityAddress = getContractsAuthorityAddress()
config.ContractsInputBoxAddress = getContractsInputBoxAddress()
Expand Down
7 changes: 1 addition & 6 deletions internal/node/config/generate/Config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ the snapshot matches the hash in the Application contract."""
# Rollups
#

[rollups.CARTESI_EPOCH_LENGTH_IN_BLOCKS]
[rollups.CARTESI_EPOCH_LENGTH]
default = "7200" # 1 day (average) in blocks (considering one block is mined every 12 seconds)
go-type = "uint64"
description = """
Expand Down Expand Up @@ -101,11 +101,6 @@ go-type = "string"
description = """
Address of the DApp's contract."""

[contracts.CARTESI_CONTRACTS_APPLICATION_DEPLOYMENT_BLOCK_NUMBER]
go-type = "int64"
description = """
Block in which the DApp's contract was deployed."""

[contracts.CARTESI_CONTRACTS_HISTORY_ADDRESS]
go-type = "string"
description = """
Expand Down
18 changes: 3 additions & 15 deletions internal/node/config/generated.go

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

6 changes: 3 additions & 3 deletions internal/node/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ func newDispatcher(c config.NodeConfig, workDir string) services.CommandService
c.BlockchainFinalityOffset))
s.Env = append(s.Env, fmt.Sprintf("REDIS_ENDPOINT=%v", getRedisEndpoint(c)))
s.Env = append(s.Env, fmt.Sprintf("DAPP_ADDRESS=%v", c.ContractsApplicationAddress))
s.Env = append(s.Env, fmt.Sprintf("DAPP_DEPLOYMENT_BLOCK_NUMBER=%v",
c.ContractsApplicationDeploymentBlockNumber))
s.Env = append(s.Env, fmt.Sprintf("INPUT_BOX_DEPLOYMENT_BLOCK_NUMBER=%v",
c.ContractsInputBoxDeploymentBlockNumber))
s.Env = append(s.Env, fmt.Sprintf("HISTORY_ADDRESS=%v", c.ContractsHistoryAddress))
s.Env = append(s.Env, fmt.Sprintf("AUTHORITY_ADDRESS=%v", c.ContractsAuthorityAddress))
s.Env = append(s.Env, fmt.Sprintf("INPUT_BOX_ADDRESS=%v", c.ContractsInputBoxAddress))
s.Env = append(s.Env, fmt.Sprintf("RD_EPOCH_LENGTH_IN_BLOCKS=%v", c.RollupsEpochLengthInBlocks))
s.Env = append(s.Env, fmt.Sprintf("RD_EPOCH_LENGTH=%v", c.RollupsEpochLength))
s.Env = append(s.Env, fmt.Sprintf("CHAIN_ID=%v", c.BlockchainID))
s.Env = append(s.Env, fmt.Sprintf("DISPATCHER_HTTP_SERVER_PORT=%v",
getPort(c, portOffsetDispatcher)))
Expand Down
6 changes: 3 additions & 3 deletions offchain/dispatcher/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct DispatcherEnvCLIConfig {

/// Duration of rollups epoch in blocks, for which dispatcher will make claims.
#[arg(long, env, default_value = "7200")]
pub rd_epoch_length_in_blocks: u64,
pub rd_epoch_length: u64,

/// Chain ID
#[arg(long, env)]
Expand All @@ -46,7 +46,7 @@ pub struct DispatcherConfig {
pub log_config: LogConfig,
pub blockchain_config: BlockchainConfig,

pub epoch_length_in_blocks: u64,
pub epoch_length: u64,
pub chain_id: u64,
}

Expand Down Expand Up @@ -86,7 +86,7 @@ impl Config {
broker_config,
log_config,
blockchain_config,
epoch_length_in_blocks: dispatcher_config.rd_epoch_length_in_blocks,
epoch_length: dispatcher_config.rd_epoch_length,
chain_id: dispatcher_config.chain_id,
};

Expand Down
Loading

0 comments on commit 9ed81ad

Please sign in to comment.