Skip to content

Commit

Permalink
Merge branch 'evm-state-package' into testnet/persistence-logs
Browse files Browse the repository at this point in the history
  • Loading branch information
vldm committed Jan 10, 2021
2 parents a91b4f1 + 2c12185 commit 290d3ca
Show file tree
Hide file tree
Showing 38 changed files with 2,427 additions and 832 deletions.
550 changes: 304 additions & 246 deletions Cargo.lock

Large diffs are not rendered by default.

19 changes: 8 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
FROM ubuntu:20.04 as builder

RUN apt-get -y update
ENV TZ=Europe/Stockholm
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN apt-get -y update && apt-get install && \
apt-get -y install curl git libssl-dev libudev-dev make pkg-config zlib1g-dev llvm clang
RUN apt-get -y install curl git libssl-dev libudev-dev make pkg-config zlib1g-dev llvm clang

RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
RUN rustup component add rustfmt && rustup update

#Use own solana, clone for repo or add to existent repo
COPY ./ /solana
#COPY ./solana /solana
#RUN git clone https://github.com/solana-labs/solana
COPY . /solana
WORKDIR /solana
RUN cargo build --release
RUN rm /solana/target/release/deps -rf
RUN rm /solana/target/release/build -rf


FROM ubuntu:20.04 as dest
RUN apt-get update && \
apt-get -y install libssl-dev libudev-dev curl
RUN apt-get -y update
RUN apt-get -y install libssl-dev libudev-dev curl

COPY --from=builder /solana/target/release/ /usr/local/solana
COPY ./entrypoint.sh /entrypoint.sh
ENV PATH="/usr/local/solana:$PATH"

#CMD /bin/bash
# CMD /bin/bash
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p align="center">
<a href="https://velas.com">
<img alt="Solana" src="https://i.imgur.com/1AHYxYP.png" width="250" />
<img alt="Velas chain" src="https://i.imgur.com/1AHYxYP.png" width="250" />
</a>
</p>
# Building
Expand Down Expand Up @@ -29,8 +29,8 @@ $ sudo apt-get install libssl-dev libudev-dev pkg-config zlib1g-dev llvm clang
## **2. Download the source code.**

```bash
$ git clone https://github.com/velas/velas.git
$ cd velas
$ git clone https://github.com/velas/velas-chain.git
$ cd velas-chain
```

## **3. Build.**
Expand All @@ -53,7 +53,7 @@ $ cargo test
```

### EVM integration
Info about evm integration is at our [docs](https://docs.next.velas.com/evm).
Info about EVM integration is at our [docs](https://docs.next.velas.com/evm).

### Starting a local devnet
Start your own devnet locally, instructions are in the [online docs](https://docs.next.velas.com/cluster/bench-tps).
Expand Down
10 changes: 5 additions & 5 deletions bench-tps-evm/src/bench_evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use solana_evm_loader_program::scope::*;

pub const BENCH_SEED: &str = "authority";

pub fn generate_evm_keypair(seed_keypair: &Keypair) -> evm::SecretKey {
pub fn generate_evm_key(seed_keypair: &Keypair) -> evm::SecretKey {
use solana_evm_loader_program::scope::evm::rand::SeedableRng;

let mut seed = [0u8; 32];
Expand All @@ -54,8 +54,8 @@ pub fn generate_and_fund_evm_keypairs<T: 'static + Client + Send + Sync>(
let mut keypairs: Vec<_> = sources
.into_iter()
.map(|key| {
let evm_keys = generate_evm_keypair(&key);
(key, evm_keys)
let evm_key = generate_evm_key(&key);
(key, evm_key)
})
.collect();
info!("Get lamports...");
Expand Down Expand Up @@ -163,7 +163,7 @@ impl<'a> FundingTransactions<'a> for Vec<(&'a Keypair, &'a evm::SecretKey, Trans
.par_iter()
.map(|(k, evm)| {
let instructions = solana_evm_loader_program::transfer_native_to_eth_ixs(
&k.pubkey(),
k.pubkey(),
to_lamports,
evm.to_address(),
);
Expand Down Expand Up @@ -323,7 +323,7 @@ fn generate_system_txs(

let tx_call = tx_call.sign(&from.1, None);

let ix = solana_evm_loader_program::send_raw_tx(&from.0.pubkey(), tx_call);
let ix = solana_evm_loader_program::send_raw_tx(from.0.pubkey(), tx_call);

let message = Message::new(&[ix], Some(&from.0.pubkey()));

Expand Down
15 changes: 9 additions & 6 deletions core/src/evm_rpc_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ impl ChainMockERPC for ChainMockERPCImpl {
.iter()
.flatten()
.map(|tx_hash| {
evm_lock
.get_tx_receipt_by_hash(*tx_hash)
.expect("Transaction exist")
evm_lock
.get_tx_receipt_by_hash(*tx_hash)
.expect("Transaction exist")
})
.filter_map(|receipt| {
RPCTransaction::new_from_receipt(receipt, block_hash.clone()).ok()
Expand Down Expand Up @@ -278,7 +278,8 @@ impl BasicERPC for BasicERPCImpl {
) -> Result<Hex<U256>, Error> {
let bank = meta.bank(block_to_commitment(block));
let evm_state = bank.evm_state.read().unwrap();
Ok(Hex(evm_state.basic(address.0).balance))
let account = evm_state.get_account(address.0).unwrap_or_default();
Ok(Hex(account.balance))
}

fn storage_at(
Expand All @@ -303,7 +304,8 @@ impl BasicERPC for BasicERPCImpl {
) -> Result<Hex<U256>, Error> {
let bank = meta.bank(block_to_commitment(block));
let evm_state = bank.evm_state.read().unwrap();
Ok(Hex(evm_state.basic(address.0).nonce))
let account = evm_state.get_account(address.0).unwrap_or_default();
Ok(Hex(account.nonce))
}

fn code(
Expand All @@ -314,7 +316,8 @@ impl BasicERPC for BasicERPCImpl {
) -> Result<Bytes, Error> {
let bank = meta.bank(block_to_commitment(block));
let evm_state = bank.evm_state.read().unwrap();
Ok(Bytes(evm_state.basic(address.0).code))
let account = evm_state.get_account(address.0).unwrap_or_default();
Ok(Bytes(account.code))
}

fn transaction_by_hash(
Expand Down
4 changes: 4 additions & 0 deletions core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,9 +672,13 @@ fn new_banks_from_ledger(
TransactionHistoryServices::default()
};

// TODO: Add evm-state to config.
let evm_state_path = ledger_path.join("evm-state");

let (mut bank_forks, mut leader_schedule_cache, snapshot_hash) = bank_forks_utils::load(
&genesis_config,
&blockstore,
evm_state_path,
config.account_paths.clone(),
config.snapshot_config.as_ref(),
process_options,
Expand Down
14 changes: 13 additions & 1 deletion core/tests/bank_forks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ mod tests {
DEFINE_SNAPSHOT_VERSION_PARAMETERIZED_TEST_FUNCTIONS!(V1_2_0, MainnetBeta, V1_2_0_MainnetBeta);

struct SnapshotTestConfig {
evm_state_dir: TempDir,
accounts_dir: TempDir,
snapshot_dir: TempDir,
_snapshot_output_path: TempDir,
Expand All @@ -79,6 +80,7 @@ mod tests {
cluster_type: ClusterType,
snapshot_interval_slots: u64,
) -> SnapshotTestConfig {
let evm_state_dir = TempDir::new().unwrap();
let accounts_dir = TempDir::new().unwrap();
let snapshot_dir = TempDir::new().unwrap();
let snapshot_output_path = TempDir::new().unwrap();
Expand All @@ -102,6 +104,7 @@ mod tests {
};
bank_forks.set_snapshot_config(Some(snapshot_config.clone()));
SnapshotTestConfig {
evm_state_dir,
accounts_dir,
snapshot_dir,
_snapshot_output_path: snapshot_output_path,
Expand All @@ -116,6 +119,7 @@ mod tests {
old_bank_forks: &BankForks,
old_last_slot: Slot,
old_genesis_config: &GenesisConfig,
evm_state_path: &Path,
account_paths: &[PathBuf],
) {
let (snapshot_path, snapshot_package_output_path) = old_bank_forks
Expand All @@ -127,6 +131,7 @@ mod tests {
let old_last_bank = old_bank_forks.get(old_last_slot).unwrap();

let deserialized_bank = snapshot_utils::bank_from_archive(
evm_state_path,
&account_paths,
&[],
&old_bank_forks
Expand Down Expand Up @@ -213,9 +218,16 @@ mod tests {
snapshot_utils::archive_snapshot_package(&snapshot_package).unwrap();

// Restore bank from snapshot
let evm_state_path = snapshot_test_config.evm_state_dir.path();
let account_paths = &[snapshot_test_config.accounts_dir.path().to_path_buf()];
let genesis_config = &snapshot_test_config.genesis_config_info.genesis_config;
restore_from_snapshot(bank_forks, last_slot, genesis_config, account_paths);
restore_from_snapshot(
evm_state_path,
bank_forks,
last_slot,
genesis_config,
account_paths,
);
}

fn run_test_bank_forks_snapshot_n(
Expand Down
6 changes: 3 additions & 3 deletions docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
links: [
{
to: "evm",
label: "Evm integration",
label: "EVM integration",
position: "left",
},
{
Expand Down Expand Up @@ -78,12 +78,12 @@ module.exports = {
items: [
{
label: "GitHub",
href: "https://github.com/velas",
href: "https://github.com/velas/velas-chain",
},
],
},
],
copyright: `Copyright © ${new Date().getFullYear()} Velas Foundation`,
copyright: `Copyright © ${new Date().getFullYear()} Velas`,
},
},
presets: [
Expand Down
15 changes: 8 additions & 7 deletions docs/src/evm.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
title: EVM in solana
title: EVM in Solana
---

[Solana application model](apps/rent.md) is aiming to high performance by spliting its modifiable state on accounts.
While this allows to process transactions in parallel on single shard, it also introduce complication for ordinary DApps developer.
[Solana application model](apps/rent.md) is aiming to high performance by spliting its modifiable state across multiple accounts.
While this allows to process transactions in parallel on single shard, thats also introduce complication for ordinary DApps developer.
Also, most of DApps infrastructure is already relies on Solidity, and targeting Ethereum blockchain.
This two reasons can significantly slow down the spread of solana ecosystem.
These two reasons can significantly slow down the spread of solana ecosystem.

To make life of DApps developers, and integrators more easier, we at Velas introduce full hybrid of solana and EVM.

Expand All @@ -20,7 +20,8 @@ Note: EVM store tokens in nano plancks, so when you transfer for example, 5 plan

Usage:
```
/target/debug/evm-utils transfer-to-eth --help
> evm-utils transfer-to-eth --help
evm-utils-transfer-to-eth 0.1.0
Transfer solana token to EVM world
Expand All @@ -39,11 +40,11 @@ ARGS:

Example:
```
evm-utils transfer-to-eth 5 9Edb9E0B88Dbf2a29aE121a657e1860aEceaA53D
> evm-utils transfer-to-eth 5 9Edb9E0B88Dbf2a29aE121a657e1860aEceaA53D
```
Result after transaction processing:
```
[2020-12-26T15:03:01Z INFO evm_utils] Loading keypair from: /home/vladimir/.config/solana/id.json
[2020-12-26T15:03:01Z INFO evm_utils] Loading keypair from: /home/user/.config/solana/id.json
Transaction signature = 5d3eP741NYgemyM4CLmXuTEcP8f8w7QxfZ5vBxorqenEtNeSHWMFpkwtyi1meFKHVNXzDD3NbvFCExjZH79gEMKk
```

Expand Down
4 changes: 2 additions & 2 deletions docs/src/evm/bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Bridge to EVM
---

All Ethereum transaction is wrapped into native format. In order to execute native transaction,
Any Ethereum transaction is wrapped into native format. In order to execute native transaction,
someone should pay a fee in native coin.
EVM bridge is managing this routine. Its a regular web-server that wrap EVM transaction into native, and take gas price as fee.

Expand All @@ -16,4 +16,4 @@ For devnet we provide a public evm-bridge, which is located at http://bridge.nex
## Gas price, and gas limit collecting:

Every evm-bridge is responsible to set it's own commision, every evm-bridge users is paying this commission by increasing gas price in transaction.
This mechanism provide incentivise to host your own evm bridge, and increase decentralisation.
This mechanism provide incentivise to host your own evm bridge publicly, and increase decentralisation.
3 changes: 1 addition & 2 deletions evm-utils/evm-bridge/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl EvmBridge {
tx.signature.chain_id()
);

let ix = solana_evm_loader_program::send_raw_tx(&self.key.pubkey(), tx);
let ix = solana_evm_loader_program::send_raw_tx(self.key.pubkey(), tx);

let message = Message::new(&[ix], Some(&self.key.pubkey()));
let mut send_raw_tx: solana::Transaction = solana::Transaction::new_unsigned(message);
Expand Down Expand Up @@ -197,7 +197,6 @@ impl BridgeERPC for BridgeERPCImpl {
let tx: evm::Transaction = rlp::decode(&bytes.0).unwrap();
let unsigned_tx: evm::UnsignedTransaction = tx.clone().into();
let hash = unsigned_tx.signing_hash(CHAIN_ID.into());

debug!("loaded tx_hash = {}", hash);
meta.send_tx(tx)
}
Expand Down
1 change: 1 addition & 0 deletions evm-utils/evm-state/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
10 changes: 7 additions & 3 deletions evm-utils/evm-state/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ rocksdb = { version = "0.15.0", default-features = false }

primitive-types = "0.7.2"
keccak-hash = "0.5"
log = "0.4"
log = "0.4.11"
simple_logger = "1.11"
hex = "0.4.2"
serde = "1.0"
sha3 = "0.9.1"
assert_matches = "1.4"
rand = "0.7.3"
rlp = "0.4.5"
thiserror = "1.0.22"
Expand All @@ -29,10 +28,15 @@ bincode = "1.3.1"
lazy_static = "1.4.0"
bytes = "0.6.0"
snafu = "0.6.8"
derive_more = "0.99.11"

[dev-dependencies]
criterion = "0.3"
quickcheck = "0.9.2"
quickcheck_macros = "0.9.1"
rand = "0.7.3"
paste = "1.0.3"

[[bench]]
name = "bench_evm"
harness = false
harness = false
Loading

0 comments on commit 290d3ca

Please sign in to comment.