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

Merge 2.0-bridge into master #2508

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
07cddcd
chore(data_structures): rename aux.rs file for Windows compatibility
aesedepece May 29, 2024
cfa93f6
feat(c-bridge): add new config params
guidiaz Aug 19, 2024
293c9df
feat(c-bridge): count drs per state on dr_database
guidiaz Aug 19, 2024
e08f9b7
feat(c-bridge): implement new watch_dog actor
guidiaz Aug 19, 2024
2e961ee
chore: attend pr review comments
guidiaz Aug 20, 2024
8e6ff2f
fix(c-bridge): use wit/rpc client instead of tcp::socket to check wit…
guidiaz Aug 20, 2024
7156203
feat(c-bridge): count drs per state on dr_database
guidiaz Aug 19, 2024
b0c1d7e
fix(c-bridge): avoid polling query status while no new query is detected
guidiaz Sep 23, 2024
3b2aae7
fix(c-bridge): json metrics syntax
guidiaz Sep 23, 2024
ade3aef
feat(c-bridge): polish drs status metrics
guidiaz Sep 23, 2024
e0532d3
chore: attend pr review comments
guidiaz Sep 24, 2024
0c72d7f
chore: cargo clippy --fix
guidiaz Sep 24, 2024
2ee9d50
fix(c-bridge): watch_dog: witHourlyExpenditure not being reported
guidiaz Oct 9, 2024
bf4def5
feat(c-bridge): watch_dog: implement new witDailyQueries metric
guidiaz Oct 9, 2024
6f405f4
feat(c-bridge): watch_dog: implement new evmContractVersion
guidiaz Oct 10, 2024
1543175
fix(c-bridge): remove duplicated entry in wrb_abi.json
guidiaz Oct 10, 2024
8ace7be
fix(c-bridge): drsLast* metrics not being updated properly
guidiaz Oct 15, 2024
8103620
feat(c-bridge): new metrics status values
guidiaz Oct 24, 2024
07f2d1a
chore: cargo fmt --all
guidiaz Oct 24, 2024
c835336
feat(c-bridge): report metrics on minutes o'clock
guidiaz Nov 7, 2024
9095f5c
chore: cargo fmt --all
guidiaz Nov 8, 2024
33623f5
test: fix legacy tests
guidiaz Nov 8, 2024
878c703
chore: cargo.lock
guidiaz Nov 8, 2024
20cb9ae
chore: clippy --fix
guidiaz Nov 8, 2024
f6780ae
chore: indulge pedantic clippy
guidiaz Nov 11, 2024
767a00e
fix: export CLIPPY_LINTS with no \r chars
guidiaz Nov 11, 2024
94fba8a
chore: attend pr review comments
guidiaz Nov 14, 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
1 change: 1 addition & 0 deletions Cargo.lock

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

12 changes: 1 addition & 11 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,7 @@ versions:
cargo clippy -- --version

# additional clippy lints
export CLIPPY_LINTS := '-D warnings
-D clippy::cast-lossless
-D clippy::cast-possible-truncation
-D clippy::cast-possible-wrap
-D clippy::cast-precision-loss
-D clippy::cast-sign-loss
-D clippy::checked-conversions
-A clippy::upper-case-acronyms
-A clippy::uninlined-format-args
-A renamed_and_removed_lints
'
export CLIPPY_LINTS := '-D warnings -D clippy::cast-lossless -D clippy::cast-possible-truncation -D clippy::cast-possible-wrap -D clippy::cast-precision-loss -D clippy::cast-sign-loss -D clippy::checked-conversions -A clippy::upper-case-acronyms -A clippy::uninlined-format-args -A renamed_and_removed_lints'
Copy link
Member

Choose a reason for hiding this comment

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

Hahaha pretty convenient


# run clippy
clippy +flags="":
Expand Down
1 change: 1 addition & 0 deletions bridges/centralized-ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2018"
[dependencies]
actix = { version = "0.13.0", default-features = false }
async-jsonrpc-client = { git = "https://github.com/witnet/async-jsonrpc-client", features = ["tcp"], branch = "fix-tcp-leak" }
chrono = "0.4.38"
ctrlc = "3.1.3"
env_logger = "0.9.0"
envy = "0.4"
Expand Down
27 changes: 27 additions & 0 deletions bridges/centralized-ethereum/src/actors/dr_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ impl Message for SetDrState {
type Result = Result<(), ()>;
}

/// Count number of data requests in given state
pub struct CountDrsPerState;

impl Message for CountDrsPerState {
type Result = Result<(u32, u32, u32, u32), ()>;
}

impl Handler<SetDrInfoBridge> for DrDatabase {
type Result = ();

Expand Down Expand Up @@ -274,6 +281,26 @@ impl Handler<SetDrState> for DrDatabase {
}
}

impl Handler<CountDrsPerState> for DrDatabase {
type Result = Result<(u32, u32, u32, u32), ()>;

fn handle(&mut self, _msg: CountDrsPerState, _ctx: &mut Self::Context) -> Self::Result {
Ok(self.dr.iter().fold(
(0u32, 0u32, 0u32, 0u32),
|(mut drs_new, mut drs_pending, mut drs_finished, mut drs_dismissed),
(_dr_id, dr_info)| {
match dr_info.dr_state {
DrState::New => drs_new += 1,
DrState::Pending => drs_pending += 1,
DrState::Finished => drs_finished += 1,
DrState::Dismissed => drs_dismissed += 1,
};
(drs_new, drs_pending, drs_finished, drs_dismissed)
},
))
}
}

/// Required trait for being able to retrieve DrDatabase address from system registry
impl actix::Supervised for DrDatabase {}

Expand Down
17 changes: 4 additions & 13 deletions bridges/centralized-ethereum/src/actors/dr_reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,15 +653,14 @@ mod tests {
])
})
.collect();
let verbose = true;

let params_one = unwrap_batch(batch_results[0].clone());
wrb_contract_abi
.function("reportResult")
.and_then(|function| function.encode_input(&params_one.into_tokens()))
.expect("encode args failed");

let params_batch = (batch_results, verbose);
let params_batch = batch_results;
wrb_contract_abi
.function("reportResultBatch")
.and_then(|function| function.encode_input(&params_batch.into_tokens()))
Expand All @@ -682,15 +681,11 @@ mod tests {
.parse()
.unwrap(),
topics: vec![
"0x00e9413c6321ec446a267b7ebf5bb108663f2ef58b35c4f6e18905ac8f205cb2"
"0x4df64445edc775fba59db44b8001852fb1b777eea88fd54f04572dd114e3ff7f"
.parse()
.unwrap(),
],
data: web3::types::Bytes(vec![
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 248, 117, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 232, 36, 130, 44, 106, 92,
40, 222, 53, 104, 223, 153, 96, 77, 104, 233, 253, 156, 140,
]),
data: web3::types::Bytes(hex::decode("0000000000000000000000000000000000000000000000000000000000001b58000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000146e6f7420696e20506f7374656420737461747573000000000000000000000000").unwrap()),
Copy link
Member

Choose a reason for hiding this comment

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

Well done. I hate how much we rely on byte arrays all across the code base and in our APIs. Hex is the way to go.

block_hash: None,
block_number: None,
transaction_hash: None,
Expand All @@ -700,13 +695,9 @@ mod tests {
log_type: None,
removed: None,
};

assert_eq!(
parse_batch_report_error_log(&wrb_contract_abi, log_posted_result),
Some((
U256::from(63605),
String::from("WitnetOracle: query not in Posted status"),
))
Some((U256::from(7_000), String::from("not in Posted status"),))
);
}

Expand Down
8 changes: 4 additions & 4 deletions bridges/centralized-ethereum/src/actors/dr_sender/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ fn deserialize_dr_collateral_one_nanowit() {
assert_eq!(total_value, 20_000_000);

let dro_bytes = dro.to_pb_bytes().unwrap();
let err = deserialize_and_validate_dr_bytes(&dro_bytes, 1, total_value).unwrap_err();
assert_eq!(err.encode_cbor(), vec![216, 39, 129, 24, 224]);
let err = deserialize_and_validate_dr_bytes(&dro_bytes, total_value, 1).unwrap_err();
assert_eq!(err.encode_cbor(), vec![216, 39, 129, 24, 225]);
}

#[test]
Expand All @@ -97,8 +97,8 @@ fn deserialize_dr_value_overflow() {
};

let dro_bytes = dro.to_pb_bytes().unwrap();
let err = deserialize_and_validate_dr_bytes(&dro_bytes, 0, 1).unwrap_err();
assert_eq!(err.encode_cbor(), vec![216, 39, 129, 24, 224]);
let err = deserialize_and_validate_dr_bytes(&dro_bytes, 1, 1).unwrap_err();
assert_eq!(err.encode_cbor(), vec![216, 39, 129, 24, 225]);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion bridges/centralized-ethereum/src/actors/eth_poller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl EthPoller {
);
last_dr_id = skip_first;
}
while last_dr_id < next_dr_id {
while last_dr_id + 1 < next_dr_id {
let init_index = usize::try_from(last_dr_id + 1).unwrap();
let last_index = match next_dr_id.cmp(&(last_dr_id + max_batch_size)) {
std::cmp::Ordering::Greater => {
Expand Down
3 changes: 3 additions & 0 deletions bridges/centralized-ethereum/src/actors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ pub mod eth_poller;

/// wit_poller actor module
pub mod wit_poller;

/// watch_dog actor module
pub mod watch_dog;
Loading