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

Bridge/watch dog #2481

Open
wants to merge 83 commits into
base: 2.0-master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
bca4401
feat(data_structures): add basic staking tracker with tests
aesedepece Jun 13, 2023
adb1f05
feat(data_structures): adapt stakes tracker to latest specs
aesedepece Oct 16, 2023
22c6672
feat: add StakeTransaction (split commit)
Tommytrg Oct 9, 2023
fca76af
feat(data_structures): add transaction factories for `StakeTransaction`
aesedepece Oct 30, 2023
824166a
feat(data_structures): add support for `UnstakeTransaction`
Tommytrg Oct 20, 2023
10472e5
feat(data_structures): allow backwards-compatibility of key data stru…
aesedepece Nov 20, 2023
6009e9b
fix(tests): fix some tests that rely on block hashes
aesedepece Nov 21, 2023
25e1f10
fix(node): make session message decoding backwards-compatible
aesedepece Nov 21, 2023
188f462
feat(node): make 2.0 codebase able to sync to V1_6
aesedepece Nov 21, 2023
d307d68
chore(data_structures): commit missing module
aesedepece Nov 21, 2023
ced0133
feat(jsonrpc): implement method for staking
Tommytrg Nov 21, 2023
f5d85a1
feat(node): staking CLI client
Tommytrg Nov 23, 2023
33ab7fb
feat(node): perform further integration of staking methods
aesedepece Jan 4, 2024
a814e0c
fix(validations): fix mismatch in superblock validations
aesedepece Nov 27, 2023
49f6cda
tests: add missing superblock_period arg in validate_commit_transaction
Tommytrg Jan 10, 2024
9cf332b
refactor: fix clippy errors
Tommytrg Jan 10, 2024
f5a5b0b
feat(data_structures): implement protocol versions controller
aesedepece Jan 19, 2024
0618bd3
feat(data_structures): enable protocol versions injection through config
aesedepece Jan 25, 2024
35bc88a
feat(data_structures): enable multiple withdrawers for a single valid…
aesedepece Jan 26, 2024
30bf140
feat(node): make mining aware of protocol versions
aesedepece Feb 2, 2024
6da1773
feat(node): ask for confirmation when creating staking transactions
aesedepece Feb 2, 2024
f894632
feat(validations): make block signature validations aware of protocol…
aesedepece Feb 2, 2024
88f04ae
fix(validations): solve synchronization and bootstrapping issues
aesedepece Feb 5, 2024
7c749f8
fix(wallet): fix keypair decoding from storage
aesedepece Feb 9, 2024
c131f74
feat(data_structures): incorporate stakes tracker into ChainState
aesedepece Feb 15, 2024
4cc3a8c
feat(node): process stake transactions when consolidating blocks
aesedepece Feb 22, 2024
cf3885f
feat(node): complete stake transaction implementation
aesedepece Feb 26, 2024
e6c963e
feat(node): add stake transaction block weight checks
aesedepece Feb 26, 2024
2e84cff
feat(jsonrpc): implement query stakes method
Tommytrg Feb 29, 2024
ef7bf95
feat(CLI): implement method for querying stakes
Tommytrg Mar 6, 2024
ed093ae
feat(validations): create eligibility module and isolate legacy minin…
aesedepece Feb 27, 2024
508bb00
feat(validations): implement new eligibility functions
aesedepece Mar 18, 2024
e84fb24
feat(node): integrate PoS eligibility into block proposing
aesedepece Apr 24, 2024
f743a98
fix(validations): fix compilation issues due to missing traits after …
drcpu-github May 1, 2024
b622aa6
fix(schemas): remove optional label from ValueTransferOutput in Stake…
drcpu-github May 1, 2024
7a3d43f
fix(mining): abort trying to mine a block when the node is not eligible
drcpu-github May 1, 2024
3db22d1
feat(validations): update block comparison and validation with wit/2 …
drcpu-github May 1, 2024
f0d8697
fix(validations): move mint transaction validation after staking tran…
drcpu-github May 2, 2024
701ca01
feat(mining): remove staking transactions from the pool once they are…
drcpu-github May 2, 2024
b2eb3ae
feat(mining): reset collateral age of the validator which mined the l…
drcpu-github May 2, 2024
ad2955a
chore(format): edit code style in validations to make Cargo formatter…
drcpu-github May 3, 2024
f8e7197
fix(cli): when require_confirmation is false, the staking transaction…
drcpu-github May 2, 2024
14752ce
(fix): switch query-stakes arguments
drcpu-github May 6, 2024
28c567c
fix(mining): fix consolidating the genesis block (current epoch is st…
drcpu-github May 6, 2024
02dccce
feat(cli): make all stake arguments required and explicitly check val…
drcpu-github May 7, 2024
793ff18
Applied suggestions
drcpu-github May 14, 2024
cb05de5
fix(mining): do not include multiple staking transactions for a valid…
drcpu-github May 16, 2024
1df5651
chore: fix netcat & upgrade ubuntu
aeweda Mar 18, 2024
0e1be39
fix: return platform specification
aeweda Mar 18, 2024
8ec3a34
test(superblock): update two_thirds_consensus
Tommytrg Jan 30, 2024
a9b5fe1
chore(cargo): adapt codebase to latest Rust (1.77)
Tommytrg Mar 25, 2024
de5775e
chore(data_structures): rename aux.rs file for Windows compatibility
aesedepece May 29, 2024
70761df
feat: implement HttpHead as new RADType
guidiaz Oct 10, 2023
8c75da6
chore(c-bridge): refactor config
guidiaz Mar 1, 2024
3c8c361
chore(c-bridge): deprecate cli's post-dr
guidiaz Mar 1, 2024
e3e6852
chore(c-bridge): upgrade wrb_abi
guidiaz Mar 1, 2024
87ce5ca
feat(c-bridge): dr_database: adapt to wsb 2.0
guidiaz Mar 1, 2024
eca2297
feat(c-bridge): dr_reporter: new feats
guidiaz Mar 1, 2024
e627e3c
feat(c-bridge): dr_sender: new feats
guidiaz Mar 1, 2024
bad4a42
feat(c-bridge): eth_poller: new feats
guidiaz Mar 1, 2024
4386d7f
feat(c-bridge): wit_poller: new feats
guidiaz Mar 1, 2024
2f9ed73
chore(c-bridge): bump binary version to 2.0.0
guidiaz Mar 1, 2024
5611fd3
chore(c-bridge): cargo fmt --all
guidiaz Mar 1, 2024
c5697df
chore(c-bridge): cargo clippy --fix
guidiaz Mar 1, 2024
f1491af
chore: bump main crate version to 2.0.0
guidiaz Mar 1, 2024
e93f9bd
fix: wip...
guidiaz Mar 5, 2024
f4f236f
chore: upgrade bridge example toml
guidiaz Mar 7, 2024
a7d970d
chore: upgrade bridge/wrb_abi
guidiaz Mar 7, 2024
71be57f
fix(c-bridge): web3 calls parameters
guidiaz Mar 7, 2024
b842f39
chore(c-bridge): polish logs
guidiaz Mar 7, 2024
afd6a39
chore: upgrade binary crate versions to 2.0.0
guidiaz Mar 7, 2024
0acccab
chore: cargo fmt --all
guidiaz Mar 7, 2024
ce8e041
fix(bridge): dismiss unavailable queries detected by eth_poller
guidiaz May 13, 2024
3d6efdc
feat(c-bridge): loop on query status batches until head is reached
guidiaz May 13, 2024
5db1043
chore(c-bridge): attend pr review comments
guidiaz May 13, 2024
b26a88e
feat(c-brige): force min collateral
guidiaz May 31, 2024
5ec6673
chore: attend pr review comments
guidiaz Jun 4, 2024
c756357
feat(c-bridge): add new config params
guidiaz Aug 19, 2024
2b07db1
feat(c-bridge): count drs per state on dr_database
guidiaz Aug 19, 2024
782064e
feat(c-bridge): implement new watch_dog actor
guidiaz Aug 19, 2024
6203494
chore: attend pr review comments
guidiaz Aug 20, 2024
a8fadb7
fix(c-bridge): use wit/rpc client instead of tcp::socket to check wit…
guidiaz Aug 20, 2024
092ba76
chore: fix deps to create::staking::helpers
guidiaz Aug 20, 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
300 changes: 265 additions & 35 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "witnet"
version = "1.7.1"
version = "2.0.0"
authors = ["Witnet Foundation <[email protected]>"]
publish = false
repository = "witnet/witnet-rust"
Expand Down Expand Up @@ -35,6 +35,7 @@ lazy_static = "1.4.0"
log = "0.4.8"
num-format = "0.4.0"
prettytable-rs = { version = "0.10.0", default-features = false }
qrcode = "0.12"
sentry = { version = "0.29.3", features = ["log"], optional = true }
serde_json = "1.0.47"
structopt = "0.3.9"
Expand Down
45 changes: 25 additions & 20 deletions bridges/centralized-ethereum/.env.example
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
# Sample env file
# Note that the bridge does not read .env files, you need to import these variables into the environment using some external tool
# adjustable params
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_ETH_ACCOUNT: "0x8c49CAfC4542D9EA9107D4E48412ACEd2A68aA77"
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_GAS_LIMITS: "report_result = 3_000_000"
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_NUM_CONFIRMATIONS: 8
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_WITNET_JSONRPC_ADDR: "10.5.1.4:21338"
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_WRB_CONTRACT_ADDR: "0x58D8ECe142c60f5707594a7C1D90e46eAE5AF431"
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_DR_FEE_NANOWITS: 10000
# not-to-be-changed params
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_ETH_CLIENT_URL: "http://gateway:8535"
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_MAX_DR_VALUE_NANOWITS: 100000000000 # 1 WIT
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_MAX_RESULT_SIZE: 100 # 100 bytes
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_REQUEST_EXAMPLE_CONTRACT_ADDR: "0xEaA9e7Ea612b169f5b41cfF86dA6322f57264a19"
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_STORAGE: "db_path = \"data/polygon_goerli\""
# Note that the bridge does not read .env files, you need to import these variables
# into the environment using some external tool

WITNET_CENTRALIZED_ETHEREUM_BRIDGE_ETH_FROM: "0x8c49CAfC4542D9EA9107D4E48412ACEd2A68aA77"
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_ETH_FROM_BALANCE_THRESHOLD: 100000000000000000 # 0.1 ETH
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_ETH_GAS_LIMITS: "report_result = 3_000_000" # (optional)
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_ETH_JSONRPC_URL: "http://gateway:8535"
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_ETH_MAX_BATCH_SIZE: 64
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_ETH_NANOWIT_WEI_PRICE: 10000 # Price of nanoWIT in WEI (optional)
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_ETH_NEW_DRS_POLLING_RATE_MS: 30000 # 30 secs, not less than average EVM's block period
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_ETH_TXS_CONFIRMATIONS: 2
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_ETH_TXS_TIMEOUT_MS: 900000 # 15 min
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_ETH_WITNET_ORACLE: "0x58D8ECe142c60f5707594a7C1D90e46eAE5AF431"

WITNET_CENTRALIZED_ETHEREUM_BRIDGE_WITNET_DR_MIN_COLLATERAL_NANOWITS: 20000000000 # 20 WIT
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_WITNET_DR_MAX_FEE_NANOWITS: 100000 # 0.1 milliWIT
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_WITNET_DR_MAX_RESULT_SIZE: 64 # 64 bytes
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_WITNET_DR_MAX_VALUE_NANOWITS: 100000000000 # 1 WIT
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_WITNET_DR_TXS_POLLING_RATE_MS: 45000 # 45 secs
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_WITNET_DR_TXS_TIMEOUT_MS: 600000 # 10 min

WITNET_CENTRALIZED_ETHEREUM_BRIDGE_WITNET_JSONRPC_SOCKET: "10.5.1.4:21338"
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_WITNET_TESTNET: "false"
# timing params
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_DR_TX_UNRESOLVED_TIMEOUT_MS: 600000 # 10 min
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_ETH_CONFIRMATION_TIMEOUT_MS: 900000 # 15 min
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_ETH_NEW_DR_POLLING_RATE_MS: 45000 # 45 secs
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_WIT_TALLY_POLLING_RATE_MS: 45000 # 45 secs
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_WIT_DR_SENDER_POLLING_RATE_MS: 45000 # 45 secs

WITNET_CENTRALIZED_ETHEREUM_BRIDGE_STORAGE: "db_path = \"data/storage\""
WITNET_CENTRALIZED_ETHEREUM_BRIDGE_STORAGE_SKIP_FIRST: 0
3 changes: 2 additions & 1 deletion bridges/centralized-ethereum/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "witnet-centralized-ethereum-bridge"
version = "1.7.1"
version = "2.0.0"
authors = ["Witnet Foundation <[email protected]>"]
edition = "2018"

Expand All @@ -25,3 +25,4 @@ witnet_net = { path = "../../net" }
witnet_node = { path = "../../node" }
witnet_util = { path = "../../util" }
witnet_validations = { path = "../../validations" }
web3-unit-converter = "0.1.1"
8 changes: 4 additions & 4 deletions bridges/centralized-ethereum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ We need to modify the configuration file that the bridge will use to establish c

There are some key fields that need to be edited here to make the bridge connect properly to your Ethereum/Witnet nodes. These are:

- *witnet_jsonrpc_addr*: make sure this address is identical to the jsonRPC address of your Witnet node.
- *eth_client_url*: make sure this field points to address where your ethereum client is running.
- *wrb_contract_addr*: this field should contain the address of the WitnetRequestsBoard contract you wish your node to connect to.
- *witnet_jsonrpc_socket*: make sure this address is identical to the jsonRPC address of your Witnet node.
- *eth_jsonrpc_url*: make sure this field points to address where your ethereum client is running.
- *eth_witnet_oracle*: this field should contain the address of the WitnetRequestsBoard contract you wish your node to connect to.
- *block_relay_contract_add*: this field should contain the address of the BlockRelay contract you wish your node to connect to.
- *eth_account*: this is the account you are using in your ethereum client.
- *eth_from*: this is the account you are using in your ethereum client.
- **NOTE**: In the case of using ganache-cli, this needs to be the first account, since currently the only account that can relay Witnet blocks to Ethereum is the one that
deployed the BlockRelay contract, which by default is the first account.

Expand Down
94 changes: 60 additions & 34 deletions bridges/centralized-ethereum/src/actors/dr_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,20 @@ pub struct DrInfoBridge {
}

/// Data request state
#[derive(Clone, Default, Serialize, Deserialize)]
#[derive(Clone, Copy, Default, Serialize, Deserialize)]
pub enum DrState {
/// New: the data request has just been posted to the smart contract.
/// New: a new query was detected on the Witnet Oracle contract,
/// but has not yet been attended.
#[default]
New,
/// Pending: the data request has been created and broadcast to witnet, but it has not been
/// included in a witnet block yet.
/// Pending: a data request transaction was broadcasted to the Witnet blockchain,
/// but has not yet been resolved.
Pending,
/// Finished: data request has been resolved in witnet and the result is in the smart
/// contract.
/// Finished: the data request result was reported back to the Witnet Oracle contract.
Finished,
/// Dismissed: the data request result cannot be reported back to the Witnet Oracle contract,
/// or was already reported by another bridge instance.
Dismissed,
}

impl fmt::Display for DrState {
Expand All @@ -72,24 +75,24 @@ impl fmt::Display for DrState {
DrState::New => "New",
DrState::Pending => "Pending",
DrState::Finished => "Finished",
DrState::Dismissed => "Dismissed",
};

f.write_str(s)
}
}

/// Data request states in Witnet Request Board contract
/// Possible query states in the Witnet Oracle contract
#[derive(Serialize, Deserialize, Clone)]
pub enum WitnetQueryStatus {
/// Unknown: the data request does not exist.
/// Unknown: the query does not exist, or got eventually deleted.
Unknown,
/// Posted: the data request has just been posted to the smart contract.
/// Posted: the query exists, but has not yet been reported.
Posted,
/// Reported: the data request has been resolved in witnet and the result is in the smart
/// contract.
/// Reported: some query result got stored into the WitnetOracle, although not yet finalized.
Reported,
/// Deleted: the data request has been resolved in witnet but the result was deleted.
Deleted,
/// Finalized: the query was reported, and considered to be final.
Finalized,
}

impl WitnetQueryStatus {
Expand All @@ -98,7 +101,7 @@ impl WitnetQueryStatus {
match i {
1 => WitnetQueryStatus::Posted,
2 => WitnetQueryStatus::Reported,
3 => WitnetQueryStatus::Deleted,
3 => WitnetQueryStatus::Finalized,
_ => WitnetQueryStatus::Unknown,
}
}
Expand All @@ -119,7 +122,7 @@ impl Actor for DrDatabase {
|dr_database_from_storage, act, _| match dr_database_from_storage {
Ok(dr_database_from_storage) => {
if let Some(mut dr_database_from_storage) = dr_database_from_storage {
log::info!("Load database from storage");
log::info!("Database loaded from storage");
act.dr = std::mem::take(&mut dr_database_from_storage.dr);
act.max_dr_id = dr_database_from_storage.max_dr_id;
} else {
Expand Down Expand Up @@ -164,22 +167,31 @@ impl Message for GetLastDrId {
type Result = Result<DrId, ()>;
}

/// Set data request id as "finished"
pub struct SetFinished {
/// Data Request Id
/// Set state of given data request id
pub struct SetDrState {
/// Data Request id
pub dr_id: DrId,
/// Data Request new state
pub dr_state: DrState,
}

impl Message for SetFinished {
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<(u64, u64, u64, u64), ()>;
}

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

fn handle(&mut self, msg: SetDrInfoBridge, ctx: &mut Self::Context) -> Self::Result {
let SetDrInfoBridge(dr_id, dr_info) = msg;
let dr_state = dr_info.dr_state.clone();
let dr_state = dr_info.dr_state;
self.dr.insert(dr_id, dr_info);

self.max_dr_id = cmp::max(self.max_dr_id, dr_id);
Expand Down Expand Up @@ -239,32 +251,24 @@ impl Handler<GetLastDrId> for DrDatabase {
}
}

impl Handler<SetFinished> for DrDatabase {
impl Handler<SetDrState> for DrDatabase {
type Result = Result<(), ()>;

fn handle(&mut self, msg: SetFinished, ctx: &mut Self::Context) -> Self::Result {
let SetFinished { dr_id } = msg;
fn handle(&mut self, msg: SetDrState, ctx: &mut Self::Context) -> Self::Result {
let SetDrState { dr_id, dr_state } = msg;
match self.dr.entry(dr_id) {
Entry::Occupied(entry) => {
entry.into_mut().dr_state = DrState::Finished;
log::debug!(
"Data request #{} updated to state {}",
dr_id,
DrState::Finished
);
log::debug!("Data request #{} updated to state {}", dr_id, dr_state,);
}
Entry::Vacant(entry) => {
entry.insert(DrInfoBridge {
dr_bytes: vec![],
dr_state: DrState::Finished,
dr_state,
dr_tx_hash: None,
dr_tx_creation_timestamp: None,
});
log::debug!(
"Data request #{} inserted with state {}",
dr_id,
DrState::Finished
);
log::debug!("Data request #{} inserted with state {}", dr_id, dr_state,);
}
}

Expand All @@ -277,6 +281,28 @@ impl Handler<SetFinished> for DrDatabase {
}
}

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

fn handle(&mut self, _msg: CountDrsPerState, _ctx: &mut Self::Context) -> Self::Result {
let mut drs_new = u64::default();
let mut drs_pending = u64::default();
let mut drs_finished = u64::default();
let mut drs_dismissed = u64::default();

self.dr.iter().for_each(|(_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,
};
});

Ok((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
Loading