Skip to content

Commit 5bf706c

Browse files
committed
fix fee percentage, polish debugs&prints
1 parent 0846b8d commit 5bf706c

File tree

9 files changed

+63
-49
lines changed

9 files changed

+63
-49
lines changed

Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ sqlx = { version="0.8.6", features = ["sqlite", "chrono", "runtime-tokio"] }
2828
warp = "0.3"
2929
hex = "0.4.3"
3030

31+
# logging
32+
tracing = "0.1.19"
33+
tracing-subscriber = { version = "0.3", features = ["registry", "env-filter" ] }
34+
tracing-log = "0.1.1"
35+
3136
# [patch."https://github.com/0xPARC/pod2"]
3237
# pod2 = { path = "../pod2" }
3338

ad-server/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ plonky2 = { workspace = true }
1313
pod2 = { workspace = true }
1414
dotenvy = { workspace = true }
1515
warp = { workspace = true }
16+
tracing = { workspace = true }
17+
tracing-subscriber = { workspace = true }
18+
tracing-log = { workspace = true }
1619

1720
app = { path = "../app" }
1821
common = { path = "../common" }
@@ -21,6 +24,3 @@ itertools = "0.14.0"
2124
serde = { version = "1.0", features = ["derive"] }
2225
serde_json = "1.0.143"
2326
async-recursion = "1.1.1"
24-
25-
# logging
26-
tracing = "0.1.19"

ad-server/src/eth.rs

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use alloy::{
88
signers::local::PrivateKeySigner,
99
};
1010
use anyhow::{Result, anyhow};
11+
use tracing::{debug, info};
1112

1213
use crate::Config;
1314

@@ -23,12 +24,12 @@ pub async fn send_payload(cfg: Config, b: Vec<u8>) -> Result<TxHash> {
2324
.connect(&cfg.rpc_url)
2425
.await?;
2526
let latest_block = provider.get_block_number().await?;
26-
println!("Latest block number: {latest_block}");
27+
info!("Latest block number: {latest_block}");
2728

2829
let sender = signer.address();
2930
let receiver = Address::from([0x42; 20]);
30-
dbg!(&sender);
31-
dbg!(&receiver);
31+
debug!("{}", sender);
32+
debug!("{}", receiver);
3233

3334
let sidecar: SidecarBuilder<SimpleCoder> = SidecarBuilder::from_slice(&b);
3435
let sidecar = sidecar.build()?;
@@ -39,18 +40,10 @@ pub async fn send_payload(cfg: Config, b: Vec<u8>) -> Result<TxHash> {
3940
// for a new tx, increase gas price by 10% to reduce the chances of the
4041
// nodes rejecting it (in practice increase it by 11% to ensure it passes
4142
// the miner filter)
42-
let (receipt, tx_hash) = send_tx(
43-
cfg,
44-
provider,
45-
receiver,
46-
sidecar,
47-
fees,
48-
blob_base_fee,
49-
111 / 100,
50-
)
51-
.await?;
52-
53-
println!(
43+
let (receipt, tx_hash) =
44+
send_tx(cfg, provider, receiver, sidecar, fees, blob_base_fee, 11).await?;
45+
46+
info!(
5447
"Transaction included in block {}",
5548
receipt.block_number.expect("Failed to get block number")
5649
);
@@ -93,18 +86,20 @@ async fn send_tx<'async_recursion>(
9386
sidecar: alloy::eips::eip4844::BlobTransactionSidecar,
9487
fees: Eip1559Estimation,
9588
blob_base_fee: u128,
96-
increase_ratio: u128,
89+
increase_percentage: u128,
9790
) -> Result<(TransactionReceipt, TxHash)> {
9891
let tx = TransactionRequest::default()
99-
.with_max_fee_per_gas(fees.max_fee_per_gas * increase_ratio)
100-
.with_max_priority_fee_per_gas(fees.max_priority_fee_per_gas * increase_ratio)
101-
.with_max_fee_per_blob_gas(blob_base_fee * increase_ratio)
92+
.with_max_fee_per_gas(fees.max_fee_per_gas * (100 + increase_percentage) / 100)
93+
.with_max_priority_fee_per_gas(
94+
fees.max_priority_fee_per_gas * (100 + increase_percentage) / 100,
95+
)
96+
.with_max_fee_per_blob_gas(blob_base_fee * (100 + increase_percentage) / 100)
10297
.with_to(receiver)
10398
.with_blob_sidecar(sidecar.clone());
10499

105-
dbg!(&tx.max_fee_per_gas.unwrap());
106-
dbg!(&tx.max_priority_fee_per_gas.unwrap());
107-
dbg!(&tx.max_fee_per_blob_gas.unwrap());
100+
debug!("{}", tx.max_fee_per_gas.unwrap());
101+
debug!("{}", tx.max_priority_fee_per_gas.unwrap());
102+
debug!("{}", tx.max_fee_per_blob_gas.unwrap());
108103

109104
let send_tx_result = provider.send_transaction(tx).await;
110105
let pending_tx_result = match send_tx_result {
@@ -115,62 +110,62 @@ async fn send_tx<'async_recursion>(
115110
return Err(anyhow!("rpc-error: {}", e));
116111
}
117112

118-
println!("tx err: {}", e);
119-
println!("sending tx again with 2x gas price");
113+
info!("tx err: {}", e);
114+
info!("sending tx again with 2x gas price");
120115
return send_tx(
121116
cfg,
122117
provider,
123118
receiver,
124119
sidecar,
125120
fees,
126121
blob_base_fee,
127-
increase_ratio * 2,
122+
increase_percentage + 100,
128123
)
129124
.await;
130125
}
131126
};
132-
println!("watching pending tx, timeout of {}", cfg.tx_watch_timeout);
127+
info!("watching pending tx, timeout of {}", cfg.tx_watch_timeout);
133128
let pending_tx_result = pending_tx_result
134129
.with_timeout(Some(std::time::Duration::from_secs(cfg.tx_watch_timeout)))
135130
.watch()
136131
.await;
137132

138-
dbg!("sent");
133+
debug!("sent");
139134
let tx_hash = match pending_tx_result {
140135
Ok(pending_tx) => pending_tx,
141136
Err(e) => {
142137
if e.to_string().contains("Too Many Requests") {
143138
panic!("error: {}", e);
144139
}
145140

146-
println!("tx err: {}", e);
147-
println!("sending tx again with 2x gas price");
141+
info!("tx err: {}", e);
142+
info!("sending tx again with 2x gas price");
148143
return send_tx(
149144
cfg,
150145
provider,
151146
receiver,
152147
sidecar,
153148
fees,
154149
blob_base_fee,
155-
increase_ratio * 2,
150+
increase_percentage + 100,
156151
)
157152
.await;
158153
}
159154
};
160-
println!("Pending transaction... tx hash: {}", tx_hash);
155+
info!("Pending transaction... tx hash: {}", tx_hash);
161156

162157
let receipt = match provider.get_transaction_receipt(tx_hash).await? {
163158
Some(receipt) => receipt,
164159
None => {
165-
println!("get_transaction_receipt failed, resending tx");
160+
info!("get_transaction_receipt failed, resending tx");
166161
return send_tx(
167162
cfg,
168163
provider,
169164
receiver,
170165
sidecar,
171166
fees,
172167
blob_base_fee,
173-
increase_ratio * 2,
168+
increase_percentage + 100,
174169
)
175170
.await;
176171
}
@@ -181,17 +176,16 @@ async fn send_tx<'async_recursion>(
181176

182177
#[cfg(test)]
183178
mod tests {
184-
use tracing::info;
185-
186179
use super::*;
187180

188181
// this test is mostly to check the send_payload method isolated from the
189182
// rest of the AD server logic
190183
#[tokio::test]
191184
async fn test_tx() -> anyhow::Result<()> {
185+
crate::log_init();
192186
common::load_dotenv()?;
193187
let cfg = Config::from_env()?;
194-
info!(?cfg, "Loaded config");
188+
println!("Loaded config: {:?}", cfg);
195189

196190
let tx_hash = send_payload(cfg, b"test".to_vec()).await?;
197191
dbg!(tx_hash);

ad-server/src/main.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,17 @@ pub struct PodConfig {
5151
predicates: Predicates,
5252
}
5353

54+
use tracing_subscriber::{EnvFilter, fmt, prelude::*};
55+
fn log_init() {
56+
tracing_subscriber::registry()
57+
.with(fmt::layer())
58+
.with(EnvFilter::from_default_env())
59+
.init();
60+
}
61+
5462
#[tokio::main]
5563
async fn main() -> Result<()> {
64+
log_init();
5665
common::load_dotenv()?;
5766
let cfg = Config::from_env()?;
5867
info!(?cfg, "Loaded config");
@@ -66,9 +75,9 @@ async fn main() -> Result<()> {
6675

6776
// initialize pod data
6877
let params = Params::default();
69-
println!("Prebuilding circuits to calculate vd_set...");
78+
info!("Prebuilding circuits to calculate vd_set...");
7079
let vd_set = &*DEFAULT_VD_SET;
71-
println!("vd_set calculation complete");
80+
info!("vd_set calculation complete");
7281
let predicates = build_predicates(&params);
7382
let shrunk_main_pod_build = Arc::new(ShrunkMainPodSetup::new(&params).build()?);
7483
let pod_config = PodConfig {
@@ -78,7 +87,7 @@ async fn main() -> Result<()> {
7887
};
7988

8089
let routes = endpoints::routes(cfg, db_pool, pod_config, shrunk_main_pod_build);
81-
println!("server at http://0.0.0.0:8000");
90+
info!("server at http://0.0.0.0:8000");
8291
warp::serve(routes).run(([0, 0, 0, 0], 8000)).await;
8392

8493
Ok(())

common/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ warp = { workspace = true }
1212
pod2 = { workspace = true }
1313
plonky2 = { workspace = true }
1414
itertools = "0.14.0"
15+
tracing = { workspace = true }
16+
tracing-log = { workspace = true }
1517

1618
[dev-dependencies]
1719
app = { path = "../app" }

common/src/circuits.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use pod2::{
1919
},
2020
middleware::{C, CommonCircuitData, D, F, Params, ToFields, VerifierCircuitData},
2121
};
22+
use tracing::info;
2223

2324
pub struct ShrunkMainPodSetup {
2425
params: Params,
@@ -129,7 +130,7 @@ impl ShrunkMainPodBuild {
129130
self.shrunk_main_pod
130131
.set_targets(&mut pw, &pod_proof_with_pis)?;
131132
let proof = self.circuit_data.prove(pw)?;
132-
println!("[TIME] shrunk MainPod proof took: {:?}", start.elapsed());
133+
info!("[TIME] shrunk MainPod proof took: {:?}", start.elapsed());
133134

134135
// sanity check: verify proof
135136
self.circuit_data.verify(proof.clone())?;
@@ -148,7 +149,7 @@ pub fn shrink_compress_pod(
148149
let start = Instant::now();
149150
let proof_with_pis = shrunk_main_pod_build.prove(pod)?;
150151
// let (verifier_data, common_circuit_data, proof_with_pis) = prove_pod(pod)?;
151-
println!("[TIME] plonky2 (wrapper) proof took: {:?}", start.elapsed());
152+
info!("[TIME] plonky2 (wrapper) proof took: {:?}", start.elapsed());
152153

153154
// this next line performs the method `fri_query_indices`, which is not exposed
154155
let indices = proof_with_pis

full-flow.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ tmux split-window -v
1919
tmux select-layout even-vertical
2020

2121
# run the AnchoredDatasystem server
22-
tmux send-keys -t fullflow:0.0 'cargo run --release -p ad-server' C-m
22+
tmux send-keys -t fullflow:0.0 'RUST_LOG=ad_server=debug cargo run --release -p ad-server' C-m
2323

2424
# run the Synchronizer server
2525
tmux send-keys -t fullflow:0.1 'RUST_LOG=synchronizer=debug cargo run --release -p synchronizer' C-m

synchronizer/Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ sqlx = { workspace = true }
1515
log = { workspace = true }
1616
warp = { workspace = true }
1717
hex = { workspace = true }
18+
tracing = { workspace = true }
19+
tracing-subscriber = { workspace = true }
20+
tracing-log = { workspace = true }
1821

1922
common = { path = "../common" }
2023

@@ -29,9 +32,5 @@ url = { version = "2.3.1", features = ["serde"] }
2932
# alloy-eips = { version = "1.0.30" }
3033
# alloy-network = { version = "1.0.30" }
3134

32-
# logging
33-
tracing = "0.1.19"
34-
tracing-subscriber = { version = "0.3", features = ["registry", "env-filter" ] }
35-
tracing-log = "0.1.1"
3635

3736
chrono = "0.4.42"

0 commit comments

Comments
 (0)