Skip to content

Commit

Permalink
feat(claimer): update claimer for repository
Browse files Browse the repository at this point in the history
  • Loading branch information
GMKrieger committed Jul 17, 2024
1 parent bc79bc3 commit 34698b5
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
16 changes: 7 additions & 9 deletions cmd/authority-claimer/src/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ pub trait DuplicateChecker: Debug {
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
struct Claim {
application: Address,
first_index: u64,
last_index: u64,
epoch_hash: Hash,
output_merkle_root_hash: Hash,
}

#[derive(Debug)]
Expand Down Expand Up @@ -122,9 +120,9 @@ impl DuplicateChecker for DefaultDuplicateChecker {
self.update_claims().await?;
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(),
output_merkle_root_hash: rollups_claim
.output_merkle_root_hash
.clone(),
};
Ok(self.claims.contains(&claim))
}
Expand Down Expand Up @@ -173,9 +171,9 @@ impl DefaultDuplicateChecker {
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),
output_merkle_root_hash: Hash::new(
claim_submission.claim.into(),
),
};
self.claims.insert(claim);
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/authority-claimer/src/claimer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,17 @@ where
continue;
}

let tx_hash;
info!("Sending a new rollups claim");
self.transaction_sender = self
(self.transaction_sender, tx_hash) = self
.transaction_sender
.send_rollups_claim_transaction(rollups_claim.clone())
.await
.context(TransactionSenderSnafu)?;

info!("Updating claim data in repository");
self.repository
.update_claim(rollups_claim.dapp_address)
.update_claim(rollups_claim.id, tx_hash)
.await
.context(RepositorySnafu)?;
}
Expand Down
5 changes: 5 additions & 0 deletions cmd/authority-claimer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub struct Config {
pub iconsensus_address: Address,
pub genesis_block: u64,
pub http_server_port: u16,
pub postgres_endpoint: String,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -95,6 +96,7 @@ impl Config {
tx_manager_priority: Priority::Normal,
log_config,
iconsensus_address,
postgres_endpoint: cli_config.postgres_endpoint,
genesis_block: cli_config.genesis_block,
http_server_port: cli_config.http_server_port,
})
Expand All @@ -118,6 +120,9 @@ struct AuthorityClaimerCLI {
#[arg(long, env)]
pub iconsensus_address: String,

#[arg(long, env)]
pub postgres_endpoint: String,

/// Genesis block for reading blockchain events
#[arg(long, env, default_value_t = 1)]
pub genesis_block: u64,
Expand Down
2 changes: 1 addition & 1 deletion cmd/authority-claimer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub async fn run(config: Config) -> Result<(), Box<dyn Error>> {

// Creating repository.
trace!("Creating the repository");
let repository = DefaultRepository::new("".to_string()).await?;
let repository = DefaultRepository::new(config.postgres_endpoint).await?;

// Creating the conditional signer.
let conditional_signer =
Expand Down
17 changes: 6 additions & 11 deletions cmd/authority-claimer/src/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

use crate::{
contracts::iconsensus::{IConsensus, InputRange},
contracts::iconsensus::IConsensus,
metrics::AuthorityClaimerMetrics,
rollups_events::{Address, DAppMetadata, RollupsClaim},
signer::ConditionalSigner,
Expand All @@ -23,7 +23,7 @@ use ethers::{
providers::{
Http, HttpRateLimitRetryPolicy, MockProvider, Provider, RetryClient,
},
types::{NameOrAddress, H160},
types::{NameOrAddress, H160, H256},
};
use snafu::{OptionExt, ResultExt, Snafu};
use std::{fmt::Debug, sync::Arc};
Expand All @@ -43,7 +43,7 @@ pub trait TransactionSender: Sized + Debug {
async fn send_rollups_claim_transaction(
self,
rollups_claim: RollupsClaim,
) -> Result<Self, Self::Error>;
) -> Result<(Self, H256), Self::Error>;
}

// ------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -190,20 +190,15 @@ impl TransactionSender for DefaultTransactionSender {
async fn send_rollups_claim_transaction(
self,
rollups_claim: RollupsClaim,
) -> Result<Self, Self::Error> {
) -> Result<(Self, H256), Self::Error> {
let dapp_address = rollups_claim.dapp_address.clone();

let transaction = {
let input_range = InputRange {
first_index: rollups_claim.first_index as u64,
last_index: rollups_claim.last_index as u64,
};
let call = self
.iconsensus
.submit_claim(
H160(dapp_address.inner().to_owned()),
input_range,
rollups_claim.epoch_hash.into_inner(),
rollups_claim.output_merkle_root_hash.into_inner(),
)
.from(self.from);
let to = match call.tx.to().context(InternalEthersSnafu)? {
Expand Down Expand Up @@ -234,6 +229,6 @@ impl TransactionSender for DefaultTransactionSender {
.inc();
trace!("Claim transaction confirmed: `{:?}`", receipt);

Ok(Self { tx_manager, ..self })
Ok((Self { tx_manager, ..self }, receipt.transaction_hash))
}
}
1 change: 1 addition & 0 deletions internal/node/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func newAuthorityClaimer(c config.NodeConfig, workDir string) services.CommandSe
c.BlockchainFinalityOffset))
s.Env = append(s.Env, fmt.Sprintf("REDIS_ENDPOINT=%v", getRedisEndpoint(c)))
s.Env = append(s.Env, fmt.Sprintf("ICONSENSUS_ADDRESS=%v", c.ContractsIConsensusAddress))
s.Env = append(s.Env, fmt.Sprintf("POSTGRES_ENDPOINT=%v", c.PostgresEndpoint.Value))
s.Env = append(s.Env, fmt.Sprintf("INPUT_BOX_ADDRESS=%v", c.ContractsInputBoxAddress))
s.Env = append(s.Env, fmt.Sprintf("GENESIS_BLOCK=%v",
c.ContractsInputBoxDeploymentBlockNumber))
Expand Down

0 comments on commit 34698b5

Please sign in to comment.