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

Feature add program gas station #395

Open
wants to merge 22 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
36f4267
Feat(programs): implement gas-station
gBaGu Nov 18, 2022
65cb293
Feat(programs): implement gas-station tests + small fixes
gBaGu Nov 24, 2022
72ca2c8
Feat(programs): refactoring
gBaGu Nov 24, 2022
9a32ac4
Feat(programs): add math checks, add test
gBaGu Nov 28, 2022
20ee799
Feat(programs): fix register payer test
gBaGu Nov 28, 2022
6161fcc
Merge branch 'develop' into feature-add-program-gas-station
gBaGu Dec 1, 2022
7e3c365
Feat(programs): integrate gas-station into bridge
gBaGu Dec 5, 2022
15f4b76
Chore(deps): switch to no_std borsh version
gBaGu Dec 9, 2022
a18dfef
Fix(deps): make evm dependencies optional for sdk
gBaGu Dec 12, 2022
7bc4d70
Fix(gas-station): copy evm types to gas station crate
gBaGu Dec 12, 2022
b21d662
Feat(gas-station): check evm accounts, check rent exemption, add tests
gBaGu Dec 13, 2022
490f16e
Feat(gas-station): disallow big transaction
gBaGu Dec 15, 2022
9f48a31
Feat(gas-station): fix clippy
gBaGu Dec 15, 2022
3761db1
Feat(gas-station): bump bpf version
gBaGu Jan 5, 2023
b7bed61
Feat(gas-station): add CLI command to register payer
gBaGu Jan 17, 2023
723331b
Feat(gas-station): add readme; change bridge command line args
gBaGu Jan 18, 2023
d5cd1fe
Feat(gas-station): improove logging, fix naming, change CLI args, fix…
gBaGu Jan 25, 2023
3b53bad
Feat(gas-station): add usage to script
gBaGu Jan 26, 2023
0331138
Feat(gas-station): add instruction to update filters, add tests, add …
gBaGu Jan 27, 2023
f25aa85
Merge branch 'develop' into feature-add-program-gas-station
gBaGu Feb 13, 2023
cabfaf1
Feat(evm-bridge): fix clippy
gBaGu Feb 27, 2023
4674bb2
Merge branch 'develop' into feature-add-program-gas-station
gBaGu Mar 8, 2023
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
93 changes: 61 additions & 32 deletions Cargo.lock

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

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ members = [
"evm-utils/evm-block-recovery",
"evm-utils/evm-bridge",
"evm-utils/programs/evm_loader",
"evm-utils/programs/gas_station",
"evm-utils/evm-state",
"evm-utils/evm-rpc",
"poh",
Expand Down Expand Up @@ -103,8 +104,9 @@ resolver = "2"
split-debuginfo = "unpacked"

[patch.crates-io]
primitive-types = { git = "https://github.com/velas/parity-common", tag = "primitive-types-v0.11-with-borsh-support" }
uint = { git = "https://github.com/velas/parity-common", tag = "primitive-types-v0.11-with-borsh-support" }
primitive-types = { git = "https://github.com/velas/parity-common", tag = "primitive-types-v0.11-with-borsh-support-nostd" }
rlp = { git = "https://github.com/velas/parity-common", tag = "primitive-types-v0.11-with-borsh-support-nostd" }
uint = { git = "https://github.com/velas/parity-common", tag = "primitive-types-v0.11-with-borsh-support-nostd" }
spl-memo = { git = "https://github.com/velas/spl-memo", branch = "solana-1.9.29" }
# TODO: remove once jsonrpc-core-client 18.0.1 is released
jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc", rev = "e724d087defc0af35bc1c844049d1611588d8466", version = "18.0.0" }
Expand Down
2 changes: 2 additions & 0 deletions evm-utils/evm-bridge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ hex = "0.4.2"
primitive-types = "0.11.0"
secp256k1 = { version = "0.19.0", features = ["recovery", "global-context"] }
evm-state = { path = "../evm-state" }
evm-gas-station = { path = "../programs/gas_station" }
log = "0.4.11"
jsonrpc-core = "18.0.0"
jsonrpc-core-client = { version = "18.0.0", features = ["ws"] }
Expand All @@ -39,6 +40,7 @@ jsonrpc-pubsub = "18.0.0"
jsonrpc-ws-server = "18.0.0"
snafu = "0.7"
anyhow = "1.0"
thiserror = "1.0"
tokio = "1"
txpool = { git = "https://github.com/velas/transaction-pool", tag = "v1.0.0-alpha" }
regex = "1.5.4"
Expand Down
61 changes: 61 additions & 0 deletions evm-utils/evm-bridge/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ pub struct EvmBridge {
pool: EthPool<SystemClock>,
min_gas_price: U256,
whitelist: Vec<TxFilter>,
gas_station_program_id: Option<Pubkey>,
redirect_to_proxy_filters: Vec<EvmContractToPayerKeys>,
}

impl EvmBridge {
Expand Down Expand Up @@ -237,13 +239,24 @@ impl EvmBridge {
pool,
min_gas_price,
whitelist: vec![],
gas_station_program_id: None,
redirect_to_proxy_filters: vec![],
}
}

fn set_whitelist(&mut self, whitelist: Vec<TxFilter>) {
self.whitelist = whitelist;
}

fn set_redirect_to_proxy_filters(
&mut self,
gas_station_program_id: Pubkey,
redirect_to_proxy_filters: Vec<EvmContractToPayerKeys>,
) {
self.gas_station_program_id = Some(gas_station_program_id);
self.redirect_to_proxy_filters = redirect_to_proxy_filters;
}

/// Wrap evm tx into solana, optionally add meta keys, to solana signature.
async fn send_tx(
&self,
Expand Down Expand Up @@ -990,6 +1003,43 @@ pub(crate) fn from_client_error(client_error: ClientError) -> evm_rpc::Error {
}
}

#[derive(thiserror::Error, Debug, PartialEq)]
pub enum ParseEvmContractToPayerKeysError {
#[error("Evm contract string is invalid")]
InvalidEvmContract,
#[error("Input format is invalid, provide string of the next format: \"<evm contract address>:<payer pubkey>\"")]
InvalidFormat,
#[error("Invalid pubkey")]
InvalidPubkey,
}

#[derive(Debug)]
struct EvmContractToPayerKeys {
contract: Address,
payer: Pubkey,
storage_acc: Pubkey,
}

impl FromStr for EvmContractToPayerKeys {
type Err = ParseEvmContractToPayerKeysError;

fn from_str(s: &str) -> StdResult<Self, Self::Err> {
let (addr, keys) = s
.split_once(':')
.ok_or(ParseEvmContractToPayerKeysError::InvalidFormat)?;
let (key1, key2) = keys
.split_once(':')
.ok_or(ParseEvmContractToPayerKeysError::InvalidFormat)?;
let contract = Address::from_str(addr)
.map_err(|_| ParseEvmContractToPayerKeysError::InvalidEvmContract)?;
let payer = Pubkey::from_str(key1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

gas_station ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed payer to gas_station_payer, removed address/key names

.map_err(|_| ParseEvmContractToPayerKeysError::InvalidPubkey)?;
let storage_acc = Pubkey::from_str(key2)
.map_err(|_| ParseEvmContractToPayerKeysError::InvalidPubkey)?;
Ok(Self { contract, payer, storage_acc })
}
}

#[derive(Debug, structopt::StructOpt)]
struct Args {
keyfile: Option<String>,
Expand All @@ -1016,6 +1066,11 @@ struct Args {

#[structopt(long = "whitelist-path")]
whitelist_path: Option<String>,

#[structopt(long = "gas-station")]
gas_station_program_id: Option<Pubkey>,
#[structopt(long = "redirect-to-proxy")]
redirect_contracts_to_proxy: Option<Vec<EvmContractToPayerKeys>>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can't we use Vec without option?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed option

}

impl Args {
Expand Down Expand Up @@ -1110,6 +1165,10 @@ async fn main(args: Args) -> StdResult<(), Box<dyn std::error::Error>> {
min_gas_price,
);
meta.set_whitelist(whitelist);
if let Some(redirect_list) = args.redirect_contracts_to_proxy {
let gas_station_program_id = args.gas_station_program_id.expect("gas-station program id is missing");
meta.set_redirect_to_proxy_filters(gas_station_program_id, redirect_list);
}
let meta = Arc::new(meta);

let mut io = MetaIoHandler::with_middleware(ProxyMiddleware {});
Expand Down Expand Up @@ -1283,6 +1342,8 @@ mod tests {
pool: EthPool::new(SystemClock),
min_gas_price: 0.into(),
whitelist: vec![],
gas_station_program_id: None,
redirect_to_proxy_filters: vec![],
});

let rpc = BridgeErpcImpl {};
Expand Down
Loading