Skip to content
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

feat(chain-listener): initial refactoring + tests #2232

Draft
wants to merge 44 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
b6a2304
wip
gurinderu Apr 19, 2024
0bba9a3
wip
gurinderu Apr 19, 2024
30de5f2
wip
gurinderu Apr 19, 2024
9a6840d
wip
gurinderu Apr 19, 2024
8cafb89
wip
gurinderu Apr 21, 2024
f5423ba
init bevaviour
gurinderu Apr 22, 2024
07b2429
init bevaviour
gurinderu Apr 22, 2024
eaf2434
init bevaviour
gurinderu Apr 22, 2024
b301a56
switch to mockall
gurinderu Apr 22, 2024
a02a14c
switch to mockall
gurinderu Apr 22, 2024
0948988
switch to mockall
gurinderu Apr 22, 2024
50c8133
switch to mockall
gurinderu Apr 22, 2024
87ff15e
test
gurinderu Apr 22, 2024
7a60b2f
wip
gurinderu Apr 24, 2024
84844e0
fix test
gurinderu Apr 24, 2024
a6aedbe
fix test
gurinderu Apr 24, 2024
0776e1c
fix test
gurinderu Apr 24, 2024
c06c2e8
fixes
gurinderu Apr 25, 2024
6a70628
config fix
gurinderu Apr 25, 2024
e235124
fix test
gurinderu Apr 25, 2024
539e4d2
fix fmt
gurinderu Apr 25, 2024
eb6a46f
review fixes
gurinderu Apr 26, 2024
a8cabcb
review fixes
gurinderu Apr 26, 2024
c428e85
fix fmt
gurinderu Apr 26, 2024
f2b0fcf
fix logging target
gurinderu Apr 26, 2024
067c8a7
fix accuire
gurinderu Apr 26, 2024
781e46d
fix accuire
gurinderu Apr 26, 2024
fdb9395
cli tests timeout change
gurinderu Apr 30, 2024
b532fd8
fix accuire
May 1, 2024
2bd7f7a
wip
gurinderu May 13, 2024
7cf0076
wip
gurinderu May 13, 2024
853060e
wip
gurinderu May 13, 2024
3ce6213
wip
gurinderu May 14, 2024
a13b0b8
fix
gurinderu May 14, 2024
f1c1436
fix
gurinderu May 14, 2024
325f4f8
update decider
gurinderu May 14, 2024
0923193
wip
gurinderu May 15, 2024
9385327
wip
gurinderu May 15, 2024
58bb8e7
wip
gurinderu May 15, 2024
f69b1df
wip
gurinderu May 15, 2024
6f8355f
fmt fix
gurinderu May 17, 2024
ad79f59
fix
gurinderu May 17, 2024
530ed0c
fix
gurinderu May 17, 2024
144a444
clippy fixes
gurinderu May 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ jobs:
cli:
needs:
- nox-snapshot
uses: fluencelabs/cli/.github/workflows/tests.yml@main
uses: fluencelabs/cli/.github/workflows/tests.yml@timeout
with:
nox-image: "${{ needs.nox-snapshot.outputs.nox-image }}"
ref: "timeout"
Copy link
Member

@justprosh justprosh May 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to revert it after merge


js-client:
needs:
Expand Down
94 changes: 84 additions & 10 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ enum_dispatch = "0.3.12"
serde_with = "3.7.0"
mockito = "1.2.0"
clarity = "1.3.0"
cpu-utils = "0.8.0"
ccp-shared = "0.8.0"
ccp-rpc-client = "0.8.0"
cpu-utils = "0.9.0"
ccp-shared = "0.9.0"
ccp-rpc-client = "0.9.0"
alloy-sol-types = "0.6.4"
alloy-primitives = "0.6.4"
alloy_serde_macro = "0.1.2"
Expand Down
11 changes: 10 additions & 1 deletion aquamarine/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ fn truncate(s: &str) -> &str {
pub fn builtin_log_fn(service: &str, args: &str, elapsed: FormattedDuration, particle_id: String) {
let args = truncate(args);
match service {
"array" | "cmp" | "debug" | "math" | "op" | "getDataSrv" | "run-console" | "json" => {
"run-console" => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure you want to leave it INFO?

tracing::event!(
tracing::Level::INFO,
"Executed host call {} ({}) [{}]",
args,
elapsed,
particle_id
)
}
"array" | "cmp" | "debug" | "math" | "op" | "getDataSrv" | "json" => {
tracing::event!(
tracing::Level::TRACE,
"Executed host call {} ({}) [{}]",
Expand Down
1 change: 0 additions & 1 deletion crates/chain-connector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ eyre = { workspace = true }
fluence-libp2p = { workspace = true }
serde_json = { workspace = true }
hex = { workspace = true }
server-config = { workspace = true }
clarity = { workspace = true }
tokio = { workspace = true, features = ["rt", "macros"] }
hex-utils = { workspace = true }
Expand Down
55 changes: 46 additions & 9 deletions crates/chain-connector/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::sync::Arc;

use ccp_shared::proof::CCProof;
use ccp_shared::types::{Difficulty, GlobalNonce, CUID};
use clarity::{Transaction, Uint256};
use clarity::{PrivateKey, Transaction, Uint256};
use eyre::eyre;
use futures::FutureExt;
use jsonrpsee::core::async_trait;
Expand All @@ -29,7 +29,6 @@ use hex_utils::decode_hex;
use particle_args::{Args, JError};
use particle_builtins::{wrap, CustomService};
use particle_execution::{ParticleParams, ServiceFunction};
use server_config::ChainConfig;
use types::DealId;

use crate::error::{process_response, ConnectorError};
Expand Down Expand Up @@ -72,9 +71,47 @@ pub trait ChainConnector: Send + Sync {
) -> Result<Vec<Result<Value, ConnectorError>>, ConnectorError>;
}

#[derive(Clone)]
pub struct HttpChainConnectorConfig {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still not sure that we need such a structure.

pub http_endpoint: String,
pub core_contract_address: String,
pub cc_contract_address: String,
pub market_contract_address: String,
pub network_id: u64,
pub wallet_key: PrivateKey,
/// If none, comes from the chain
pub default_base_fee: Option<u64>,
/// If none, comes from the chain
pub default_priority_fee: Option<u64>,
}

impl HttpChainConnectorConfig {
pub fn new(
http_endpoint: String,
core_contract_address: String,
cc_contract_address: String,
market_contract_address: String,
network_id: u64,
wallet_key: PrivateKey,
default_base_fee: Option<u64>,
default_priority_fee: Option<u64>,
) -> Self {
Self {
http_endpoint,
core_contract_address,
cc_contract_address,
market_contract_address,
network_id,
wallet_key,
default_base_fee,
default_priority_fee,
}
}
}

pub struct HttpChainConnector {
client: Arc<jsonrpsee::http_client::HttpClient>,
config: ChainConfig,
config: HttpChainConnectorConfig,
tx_nonce_mutex: Arc<Mutex<()>>,
host_id: PeerId,
}
Expand All @@ -84,14 +121,14 @@ pub struct CCInitParams {
pub init_timestamp: U256,
pub global_nonce: GlobalNonce,
pub current_epoch: U256,
pub epoch_duration: U256,
pub epoch_duration_sec: U256,
pub min_proofs_per_epoch: U256,
pub max_proofs_per_epoch: U256,
}

impl HttpChainConnector {
pub fn new(
config: ChainConfig,
config: HttpChainConnectorConfig,
host_id: PeerId,
) -> eyre::Result<(Arc<Self>, HashMap<String, CustomService>)> {
tracing::info!(target: "chain-connector","Connecting to chain via {}", config.http_endpoint);
Expand Down Expand Up @@ -400,7 +437,7 @@ impl ChainConnector for HttpChainConnector {
init_timestamp,
global_nonce: GlobalNonce::new(global_nonce.0),
current_epoch,
epoch_duration,
epoch_duration_sec: epoch_duration,
min_proofs_per_epoch,
max_proofs_per_epoch,
})
Expand Down Expand Up @@ -594,12 +631,12 @@ mod tests {

use crate::{
is_commitment_not_active, CCStatus, ChainConnector, CommitmentId, ConnectorError,
HttpChainConnector,
HttpChainConnector, HttpChainConnectorConfig,
};

fn get_connector(url: &str) -> Arc<HttpChainConnector> {
let (connector, _) = HttpChainConnector::new(
server_config::ChainConfig {
HttpChainConnectorConfig {
http_endpoint: url.to_string(),
cc_contract_address: "0x0E62f5cfA5189CA34E79CCB03829C064405790aD".to_string(),
core_contract_address: "0x2f5224b7Cb8bd98d9Ef61c247F4741758E8E873d".to_string(),
Expand Down Expand Up @@ -805,7 +842,7 @@ mod tests {
U256::from(0x00000000000000000000000000000000000000000000000000000000000016be)
);
assert_eq!(
init_params.epoch_duration,
init_params.epoch_duration_sec,
U256::from(0x000000000000000000000000000000000000000000000000000000000000000f)
);
assert_eq!(init_params.min_proofs_per_epoch, U256::from(5));
Expand Down
1 change: 1 addition & 0 deletions crates/chain-connector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ mod function;
pub use connector::CCInitParams;
pub use connector::ChainConnector;
pub use connector::HttpChainConnector;
pub use connector::HttpChainConnectorConfig;
pub use error::ConnectorError;
pub use function::*;
6 changes: 5 additions & 1 deletion crates/chain-listener/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ tracing = { workspace = true }
eyre = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true, features = ["rt"] }
server-config = { workspace = true }
types = { workspace = true }
libipld = { workspace = true }

Expand All @@ -43,3 +42,8 @@ peer-metrics = { workspace = true }

[dev-dependencies]
jsonrpsee = { workspace = true, features = ["server"] }
tempfile = { workspace = true }
tokio-stream = { workspace = true }
log-utils = { workspace = true }
parking_lot = { workspace = true }
mockall = "0.12.1"
Loading
Loading