Skip to content

Commit

Permalink
Eth-client: replace admin_controlled with near plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
karim-en committed Nov 15, 2022
1 parent 86d35e9 commit 49f7579
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 94 deletions.
88 changes: 5 additions & 83 deletions contracts/near/Cargo.lock

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

5 changes: 3 additions & 2 deletions contracts/near/eth-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
eth-types = { path = "../eth-types", default-features = false }
admin-controlled = { path = "../admin-controlled" }
near-sdk = "4.0.0"
wee_alloc = { version = "0.4.5", default-features = false, features = [] }
rlp = "0.4.2"
futures = "0.1.26"
primal = "0.2.3"
arrutil = "0.1.2"
ethash = { git = "https://github.com/nearprotocol/rust-ethash" }
hex = "0.4.0"
rustc-hex = "2.1.0"
borsh = "0.9.3"
near-plugins = { git = "https://github.com/aurora-is-near/near-plugins", rev = "5579de43c28984d00fa9aebc0a8e755258bba6c2" }
near-plugins-derive = { git = "https://github.com/aurora-is-near/near-plugins", rev = "5579de43c28984d00fa9aebc0a8e755258bba6c2" }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
# serde's Serialize and Deserialize traits are required for `near_bindgen` macro for non-wasm32 targets
Expand Down
4 changes: 3 additions & 1 deletion contracts/near/eth-client/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
stable-2022-07-19
[toolchain]
channel = "1.64.0"
components = ["clippy", "rustfmt"]
15 changes: 9 additions & 6 deletions contracts/near/eth-client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use admin_controlled::Mask;
use borsh::{BorshDeserialize, BorshSerialize};
use eth_types::*;
use near_sdk::collections::UnorderedMap;
use near_sdk::{assert_self, AccountId};
use near_sdk::{env, near_bindgen, PanicOnDefault};
use near_plugins::{Ownable, Pausable};
use near_plugins_derive::pause;

#[cfg(not(target_arch = "wasm32"))]
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -59,10 +60,10 @@ pub struct HeaderInfo {
pub number: u64,
}

const PAUSE_ADD_BLOCK_HEADER: Mask = 1;
pub type Mask = u128;

#[near_bindgen]
#[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)]
#[derive(BorshDeserialize, BorshSerialize, PanicOnDefault, Ownable, Pausable)]
pub struct EthClient {
/// Whether client validates the PoW when accepting the header. Should only be set to `false`
/// for debugging, testing, diagnostic purposes when used with Ganache or in PoA testnets
Expand Down Expand Up @@ -102,6 +103,7 @@ pub struct EthClient {
/// others will be immediately rejected, used in PoA testnets
trusted_signer: Option<AccountId>,
/// Mask determining all paused functions
#[deprecated]
paused: Mask,
}

Expand All @@ -122,6 +124,7 @@ impl EthClient {
let header: BlockHeader = rlp::decode(first_header.as_slice()).unwrap();
let header_hash = header.hash.unwrap().clone();
let header_number = header.number;
#[allow(deprecated)]
let mut res = Self {
validate_ethash,
dags_start_epoch,
Expand Down Expand Up @@ -150,6 +153,8 @@ impl EthClient {
number: header_number,
},
);

res.owner_set(Some(near_sdk::env::predecessor_account_id()));
res
}

Expand Down Expand Up @@ -198,14 +203,14 @@ impl EthClient {
/// Add the block header to the client.
/// `block_header` -- RLP-encoded Ethereum header;
/// `dag_nodes` -- dag nodes with their merkle proofs.
#[pause(except(owner, self))]
#[result_serializer(borsh)]
pub fn add_block_header(
&mut self,
#[serializer(borsh)] block_header: Vec<u8>,
#[serializer(borsh)] dag_nodes: Vec<DoubleNodeWithMerkleProof>,
) {
env::log_str("Add block header");
self.check_not_paused(PAUSE_ADD_BLOCK_HEADER);
let header: BlockHeader = rlp::decode(block_header.as_slice()).unwrap();

if let Some(trusted_signer) = &self.trusted_signer {
Expand Down Expand Up @@ -454,5 +459,3 @@ impl EthClient {
(H256(pair.0), H256(pair.1))
}
}

admin_controlled::impl_admin_controlled!(EthClient, paused);
2 changes: 1 addition & 1 deletion contracts/near/eth-client/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ fn get_context() -> VMContext {
signer_account_pk: "ed25519:6E8sCci9badyRkXb3JoRpBj5p8C6Tw41ELDZoiihKEtp"
.parse()
.unwrap(),
predecessor_account_id: "carol.near".parse().unwrap(),
predecessor_account_id: "alice.near".parse().unwrap(),
input: vec![],
block_index: 0,
block_timestamp: 0,
Expand Down
4 changes: 3 additions & 1 deletion contracts/near/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
stable-2022-07-19
[toolchain]
channel = "1.64.0"
components = ["clippy", "rustfmt"]

0 comments on commit 49f7579

Please sign in to comment.