Skip to content

Commit

Permalink
feat: bump contracts to 2.0-rc.2
Browse files Browse the repository at this point in the history
  • Loading branch information
gligneul committed Apr 24, 2024
1 parent a223d31 commit 5b2ad2b
Show file tree
Hide file tree
Showing 57 changed files with 2,496 additions and 3,689 deletions.
6 changes: 2 additions & 4 deletions .github/license-check/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
{
"include": ["**/*.go", "**/*.rs"],
"exclude": [
"offchain/grpc-interfaces/**",
"offchain/target/**",
"offchain/data/src/schema.rs",
"pkg/contracts/*.go",
"cmd/authority-claimer/target/**",
"pkg/contracts/**",
"pkg/readerclient/generated.go",
"pkg/inspectclient/generated.go",
"rollups-contracts/**"
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Added Rollups end-to-end test using Echo Dapp

### Changed

- Bumped Rollups Contracts to 2.0

### Removed

- Removed `advance-runner`, `dispatcher`, `graphql-server`, `host-runner`, `indexer`, `inspect-server`, and `state-server` Rust services
Expand Down
13 changes: 6 additions & 7 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,17 @@ apt-get install -y --no-install-recommends \
gnupg
EOF

# Install yarn
# Install nodejs
ARG DEBIAN_FRONTEND=noninteractive
RUN <<EOF
set -e
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
apt-get update
apt-get install -y --no-install-recommends \
nodejs \
yarn
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt-get install -y nodejs
EOF

# Install pnpm
RUN npm install -g @pnpm/exe

# Install Go
ARG GO_VERSION
RUN curl -sSL https://go.dev/dl/go${GO_VERSION}.linux-$(dpkg --print-architecture).tar.gz | \
Expand Down
10 changes: 4 additions & 6 deletions build/compose-devnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ services:
CARTESI_BLOCKCHAIN_WS_ENDPOINT: "ws://devnet:8545"
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"
CARTESI_CONTRACTS_INPUT_BOX_DEPLOYMENT_BLOCK_NUMBER: "20"
CARTESI_CONTRACTS_APPLICATION_ADDRESS: "0xb72c832dDeA10326143831F1E5F1646920C9c990"
CARTESI_CONTRACTS_ICONSENSUS_ADDRESS: "0x77e5a5fb18F72b5106621f66C704c006c6dB4578"
CARTESI_CONTRACTS_INPUT_BOX_ADDRESS: "0xA1b8EB1F13d8D5Db976a653BbDF8972cfD14691C"
CARTESI_CONTRACTS_INPUT_BOX_DEPLOYMENT_BLOCK_NUMBER: "16"
CARTESI_EPOCH_DURATION: "120"
CARTESI_FEATURE_DISABLE_MACHINE_HASH_CHECK: "true"
CARTESI_AUTH_KIND: "mnemonic"
Expand Down
4 changes: 1 addition & 3 deletions build/compose-sepolia.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ 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_ICONSENSUS_ADDRESS: "0x5827Ec9365D3a9b27bF1dB982d258Ad234D37242"
CARTESI_CONTRACTS_INPUT_BOX_ADDRESS: "0x59b22D57D4f067708AB0c00552767405926dc768"
CARTESI_CONTRACTS_INPUT_BOX_DEPLOYMENT_BLOCK_NUMBER: "3963384"
CARTESI_EPOCH_DURATION: "86400"
Expand Down
1 change: 0 additions & 1 deletion cmd/authority-claimer/Cargo.lock

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

1 change: 0 additions & 1 deletion cmd/authority-claimer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ axum = "0.7"
backoff = {version = "0.4", features = ["tokio"]}
base64 = "0.22"
clap = {version = "4.5", features = ["string", "derive", "env"]}
ethabi = "18.0"
ethers = "1.0"
ethers-signers = {version = "1.0", features = ["aws"]}
eth-state-fold = "0.9"
Expand Down
22 changes: 10 additions & 12 deletions cmd/authority-claimer/build.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

use snafu::prelude::*;
use std::error::Error;
use std::fs::File;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::str;

use eth_state_fold_types::contract;
use snafu::prelude::*;
use std::{
error::Error,
fs::File,
path::{Path, PathBuf},
process::Command,
str,
};

const ROLLUPS_CONTRACTS_URL: &str =
"https://registry.npmjs.org/@cartesi/rollups/-/rollups-1.2.0.tgz";
"https://registry.npmjs.org/@cartesi/rollups/-/rollups-2.0.0-rc.2.tgz";

fn main() -> Result<(), Box<dyn Error>> {
let tempdir = tempfile::tempdir()?;
let tarball = tempdir.path().join("rollups.tgz");
download_contracts(&tarball)?;
unzip_contracts(&tarball, tempdir.path())?;

let contracts = vec![
("consensus/authority", "Authority", "authority.rs"),
("history", "History", "history.rs"),
];
let contracts = vec![("consensus", "IConsensus", "iconsensus.rs")];
for (contract_path, contract_name, bindings_file_name) in contracts {
let source_path = path(tempdir.path(), contract_path, contract_name);
let output_path: PathBuf =
Expand Down
119 changes: 47 additions & 72 deletions cmd/authority-claimer/src/checker.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

use crate::contracts::history::{Claim, History};
use crate::rollups_events::{Address, RollupsClaim};
use crate::{
contracts::iconsensus::IConsensus,
rollups_events::{Address, Hash, RollupsClaim},
};
use async_trait::async_trait;
use ethers::{
self,
contract::ContractError,
providers::{
Http, HttpRateLimitRetryPolicy, Middleware, Provider, RetryClient,
},
types::H160,
types::{Address as EthersAddress, H160},
};
use snafu::{ensure, ResultExt, Snafu};
use std::sync::Arc;
use std::{collections::HashMap, fmt::Debug};
use std::{collections::HashSet, fmt::Debug, sync::Arc};
use tracing::trace;
use url::{ParseError, Url};

Expand All @@ -36,11 +37,20 @@ pub trait DuplicateChecker: Debug {
// DefaultDuplicateChecker
// ------------------------------------------------------------------------------------------------

#[derive(Debug, Clone, Hash, Eq, PartialEq)]
struct Claim {
application: Address,
first_index: u64,
last_index: u64,
epoch_hash: Hash,
}

#[derive(Debug)]
pub struct DefaultDuplicateChecker {
provider: Arc<Provider<RetryClient<Http>>>,
history: History<Provider<RetryClient<Http>>>,
claims: HashMap<Address, Vec<Claim>>,
iconsensus: IConsensus<Provider<RetryClient<Http>>>,
from: EthersAddress,
claims: HashSet<Claim>,
confirmations: usize,
next_block_to_read: u64,
}
Expand All @@ -66,24 +76,13 @@ pub enum DuplicateCheckerError {
latest
))]
DepthTooHigh { depth: u64, latest: u64 },

#[snafu(display(
"Claim mismatch; blockchain expects [{}, ?], but got claim with [{}, {}]",
expected_first_index,
claim_first_index,
claim_last_index
))]
ClaimMismatch {
expected_first_index: u128,
claim_first_index: u128,
claim_last_index: u128,
},
}

impl DefaultDuplicateChecker {
pub async fn new(
http_endpoint: String,
history_address: Address,
iconsensus: Address,
from: EthersAddress,
confirmations: usize,
genesis_block: u64,
) -> Result<Self, DuplicateCheckerError> {
Expand All @@ -95,14 +94,15 @@ impl DefaultDuplicateChecker {
INITIAL_BACKOFF,
);
let provider = Arc::new(Provider::new(retry_client));
let history = History::new(
H160(history_address.inner().to_owned()),
let iconsensus = IConsensus::new(
H160(iconsensus.inner().to_owned()),
provider.clone(),
);
let mut checker = Self {
provider,
history,
claims: HashMap::new(),
iconsensus,
from,
claims: HashSet::new(),
confirmations,
next_block_to_read: genesis_block,
};
Expand All @@ -120,27 +120,13 @@ impl DuplicateChecker for DefaultDuplicateChecker {
rollups_claim: &RollupsClaim,
) -> Result<bool, Self::Error> {
self.update_claims().await?;
let expected_first_index = self
.claims // HashMap => DappAddress to Vec<Claim>
.get(&rollups_claim.dapp_address) // Gets a Option<Vec<Claim>>
.and_then(|claims| claims.last()) // Back to only one Option
.map(|claim| claim.last_index + 1) // Maps to a number
.unwrap_or(0); // If None, unwrap to 0
if rollups_claim.first_index == expected_first_index {
// This claim is the one the blockchain expects, so it is not considered duplicate.
Ok(false)
} else if rollups_claim.last_index < expected_first_index {
// This claim is already on the blockchain.
Ok(true)
} else {
// This claim is not on blockchain, but it isn't the one blockchain expects.
// If this happens, there is a bug on the dispatcher.
Err(DuplicateCheckerError::ClaimMismatch {
expected_first_index,
claim_first_index: rollups_claim.first_index,
claim_last_index: rollups_claim.last_index,
})
}
let claim = Claim {
application: rollups_claim.dapp_address.clone(),
first_index: rollups_claim.first_index as u64,
last_index: rollups_claim.last_index as u64,
epoch_hash: rollups_claim.epoch_hash.clone(),
};
Ok(self.claims.contains(&claim))
}
}

Expand All @@ -167,44 +153,33 @@ impl DefaultDuplicateChecker {
return Ok(());
}

let new_claims: Vec<(Address, Claim)> = self
.history
.new_claim_to_history_filter()
let claims = self
.iconsensus
.claim_submission_filter()
.from_block(self.next_block_to_read)
.to_block(latest)
.topic1(self.from)
.query()
.await
.context(ContractSnafu)?
.into_iter()
.map(|e| (Address::new(e.dapp.into()), e.claim))
.collect();
.context(ContractSnafu)?;

trace!(
"read new claims {:?} from block {} to {}",
new_claims,
claims,
self.next_block_to_read,
latest
);
self.append_claims(new_claims);

for claim_submission in claims.into_iter() {
let claim = Claim {
application: Address::new(claim_submission.app_contract.into()),
first_index: claim_submission.input_range.first_index,
last_index: claim_submission.input_range.last_index,
epoch_hash: Hash::new(claim_submission.epoch_hash),
};
self.claims.insert(claim);
}
self.next_block_to_read = latest + 1;

Ok(())
}

// Appends new claims to the [Address => Vec<Claim>] hashmap cache.
fn append_claims(&mut self, new_claims: Vec<(Address, Claim)>) {
if new_claims.is_empty() {
return;
}
for (dapp_address, new_claim) in new_claims {
match self.claims.get_mut(&dapp_address) {
Some(old_claims) => {
old_claims.push(new_claim);
}
None => {
self.claims.insert(dapp_address, vec![new_claim]);
}
}
}
}
}
9 changes: 4 additions & 5 deletions cmd/authority-claimer/src/claimer.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

use async_trait::async_trait;
use snafu::ResultExt;
use std::fmt::Debug;
use tracing::{info, trace};

use crate::{
checker::DuplicateChecker, listener::BrokerListener,
sender::TransactionSender,
};
use async_trait::async_trait;
use snafu::ResultExt;
use std::fmt::Debug;
use tracing::{info, trace};

/// The `Claimer` starts an event loop that waits for claim messages
/// from the broker, and then sends the claims to the blockchain. It checks to
Expand Down
Loading

0 comments on commit 5b2ad2b

Please sign in to comment.