-
Notifications
You must be signed in to change notification settings - Fork 185
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
Changes from all commits
b6a2304
0bba9a3
30de5f2
9a6840d
8cafb89
f5423ba
07b2429
eaf2434
b301a56
a02a14c
0948988
50c8133
87ff15e
7a60b2f
84844e0
a6aedbe
0776e1c
c06c2e8
6a70628
e235124
539e4d2
eb6a46f
a8cabcb
c428e85
f2b0fcf
067c8a7
781e46d
fdb9395
b532fd8
2bd7f7a
7cf0076
853060e
3ce6213
a13b0b8
f1c1436
325f4f8
0923193
9385327
58bb8e7
f69b1df
6f8355f
ad79f59
530ed0c
144a444
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure you want to leave it |
||
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 {} ({}) [{}]", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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}; | ||
|
@@ -72,9 +71,47 @@ pub trait ChainConnector: Send + Sync { | |
) -> Result<Vec<Result<Value, ConnectorError>>, ConnectorError>; | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct HttpChainConnectorConfig { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
} | ||
|
@@ -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); | ||
|
@@ -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, | ||
}) | ||
|
@@ -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(), | ||
|
@@ -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)); | ||
|
There was a problem hiding this comment.
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