Skip to content

Commit 0ed58a1

Browse files
authored
Merge branch 'master' into bush/taproot-validation
2 parents b3f523d + 370a65d commit 0ed58a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+459
-2900
lines changed

.github/workflows/build-dev.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,15 @@ env:
2727
jobs:
2828
build:
2929
runs-on: ubuntu-latest
30-
container: defi/ain-builder:latest
3130
strategy:
3231
matrix:
3332
target: [x86_64-pc-linux-gnu, x86_64-w64-mingw32, x86_64-apple-darwin]
33+
include:
34+
- container: defi/ain-builder:latest
35+
- target: x86_64-w64-mingw32
36+
container: defi/ain-win-builder:latest
37+
container:
38+
image: ${{ matrix.container }}
3439
env:
3540
TARGET: ${{matrix.target}}
3641

.github/workflows/build-release.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@ env:
1414
jobs:
1515
create-release:
1616
runs-on: ubuntu-latest
17-
container: defi/ain-builder:latest
1817
if: startsWith(github.ref, 'refs/tags/')
1918
strategy:
2019
matrix:
2120
target: [x86_64-pc-linux-gnu, aarch64-linux-gnu, x86_64-w64-mingw32, x86_64-apple-darwin, aarch64-apple-darwin]
21+
include:
22+
- container: defi/ain-builder:latest
23+
- target: x86_64-w64-mingw32
24+
container: defi/ain-win-builder:latest
25+
container:
26+
image: ${{ matrix.container }}
2227
env:
2328
TARGET: ${{matrix.target}}
2429

.github/workflows/build-staging.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ jobs:
1313
# these don't create end artifacts to use
1414
stage-release:
1515
runs-on: ubuntu-latest
16-
container: defi/ain-builder:latest
1716
strategy:
1817
matrix:
1918
target: [x86_64-pc-linux-gnu, aarch64-linux-gnu, x86_64-w64-mingw32, x86_64-apple-darwin, aarch64-apple-darwin]
19+
include:
20+
- container: defi/ain-builder:latest
21+
- target: x86_64-w64-mingw32
22+
container: defi/ain-win-builder:latest
23+
container:
24+
image: ${{ matrix.container }}
2025
env:
2126
TARGET: ${{matrix.target}}
2227

.github/workflows/tests-frontier.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: Tests - DeFiCh/metachain-ts-suite
22

33
on:
44
workflow_dispatch:
5+
push:
6+
branches:
7+
- master
58
pull_request:
69
branches:
710
- master

lib/ain-evm/src/backend.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ struct OverlayData {
6464
storage: HashMap<H256, H256>,
6565
}
6666

67-
#[derive(Debug, Clone)]
68-
struct Overlay {
67+
#[derive(Debug, Clone, Default)]
68+
pub struct Overlay {
6969
state: HashMap<H160, OverlayData>,
7070
changeset: Vec<HashMap<H160, OverlayData>>,
7171
deletes: HashSet<H160>,
@@ -145,6 +145,7 @@ impl EVMBackend {
145145
trie_store: Arc<TrieDBStore>,
146146
storage: Arc<Storage>,
147147
vicinity: Vicinity,
148+
overlay: Option<Overlay>,
148149
) -> Result<Self> {
149150
let state = trie_store
150151
.trie_db
@@ -156,7 +157,7 @@ impl EVMBackend {
156157
trie_store,
157158
storage,
158159
vicinity,
159-
overlay: Overlay::new(),
160+
overlay: overlay.unwrap_or_default(),
160161
})
161162
}
162163

lib/ain-evm/src/core.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use parking_lot::Mutex;
2828
use vsdb_core::vsdb_set_base_dir;
2929

3030
use crate::{
31-
backend::{BackendError, EVMBackend, Vicinity},
31+
backend::{BackendError, EVMBackend, Overlay, Vicinity},
3232
block::INITIAL_BASE_FEE,
3333
blocktemplate::BlockTemplate,
3434
executor::{AinExecutor, ExecutorContext, TxResponse},
@@ -239,7 +239,7 @@ impl EVMCoreService {
239239
self.trie_store.flush()
240240
}
241241

242-
pub fn call(&self, arguments: EthCallArgs) -> Result<TxResponse> {
242+
pub fn call(&self, arguments: EthCallArgs, overlay: Option<Overlay>) -> Result<TxResponse> {
243243
let EthCallArgs {
244244
caller,
245245
to,
@@ -276,6 +276,7 @@ impl EVMCoreService {
276276
Arc::clone(&self.trie_store),
277277
Arc::clone(&self.storage),
278278
vicinity,
279+
overlay,
279280
)
280281
.map_err(|e| format_err!("------ Could not restore backend {}", e))?;
281282

@@ -766,6 +767,7 @@ impl EVMCoreService {
766767
Arc::clone(&self.trie_store),
767768
Arc::clone(&self.storage),
768769
vicinity,
770+
None,
769771
)
770772
.map_err(|e| format_err!("Could not restore backend {}", e))?;
771773
backend.update_vicinity_from_tx(tx)?;
@@ -832,6 +834,7 @@ impl EVMCoreService {
832834
Arc::clone(&self.trie_store),
833835
Arc::clone(&self.storage),
834836
Vicinity::default(),
837+
None,
835838
)?;
836839
Ok(backend.get_account(&address))
837840
}
@@ -901,6 +904,7 @@ impl EVMCoreService {
901904
Arc::clone(&self.trie_store),
902905
Arc::clone(&self.storage),
903906
vicinity,
907+
None,
904908
)
905909
}
906910

@@ -918,6 +922,7 @@ impl EVMCoreService {
918922
),
919923
..Vicinity::default()
920924
},
925+
None,
921926
)
922927
}
923928

lib/ain-evm/src/evm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ impl EVMServices {
526526
Arc::clone(&self.core.trie_store),
527527
Arc::clone(&self.storage),
528528
vicinity.clone(),
529+
None,
529530
)?;
530531

531532
let template = BlockTemplate::new(vicinity, ctx, backend);

lib/ain-evm/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Defichain EVM consensus, runtime and storage implementation
22
3-
mod backend;
3+
pub mod backend;
44
pub mod block;
55
pub mod blocktemplate;
66
pub mod bytes;

lib/ain-evm/src/trie.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ impl TrieDBStore {
6666
Arc::clone(trie_store),
6767
Arc::clone(storage),
6868
Vicinity::default(),
69+
None,
6970
)
7071
.expect("Could not restore backend");
7172

lib/ain-grpc/src/call_request.rs

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
use ain_evm::bytes::Bytes;
2-
use ethereum::AccessListItem;
3-
use ethereum_types::{H160, U256};
1+
use std::collections::{BTreeMap, HashMap};
2+
3+
use ain_evm::{backend::Overlay, bytes::Bytes};
4+
use ethereum::{AccessListItem, Account};
5+
use ethereum_types::{H160, H256, U256};
46
use jsonrpsee::core::Error;
57
use serde::Deserialize;
68

@@ -127,3 +129,53 @@ impl CallRequest {
127129
}
128130
}
129131
}
132+
133+
// State override
134+
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
135+
#[serde(deny_unknown_fields)]
136+
#[serde(rename_all = "camelCase")]
137+
pub struct CallStateOverride {
138+
/// Fake balance to set for the account before executing the call.
139+
pub balance: Option<U256>,
140+
/// Fake nonce to set for the account before executing the call.
141+
pub nonce: Option<U256>,
142+
/// Fake EVM bytecode to inject into the account before executing the call.
143+
pub code: Option<Bytes>,
144+
/// Fake key-value mapping to override all slots in the account storage before
145+
/// executing the call.
146+
pub state: Option<BTreeMap<H256, H256>>,
147+
/// Fake key-value mapping to override individual slots in the account storage before
148+
/// executing the call.
149+
pub state_diff: Option<BTreeMap<H256, H256>>,
150+
}
151+
152+
pub fn override_to_overlay(r#override: BTreeMap<H160, CallStateOverride>) -> Overlay {
153+
let mut overlay = Overlay::default();
154+
155+
for (address, state_override) in r#override {
156+
let code = state_override.code.map(|b| b.into_vec());
157+
let mut storage = state_override
158+
.state
159+
.unwrap_or_default()
160+
.into_iter()
161+
.collect::<HashMap<_, _>>();
162+
163+
let account = Account {
164+
balance: state_override.balance.unwrap_or_default(),
165+
nonce: state_override.nonce.unwrap_or_default(),
166+
storage_root: H256::zero(),
167+
code_hash: H256::zero(),
168+
};
169+
170+
let reset_storage = storage.is_empty();
171+
if let Some(diff) = state_override.state_diff {
172+
for (k, v) in diff {
173+
storage.insert(k, v);
174+
}
175+
}
176+
177+
overlay.apply(address, account, code, storage, reset_storage);
178+
}
179+
180+
overlay
181+
}

lib/ain-grpc/src/rpc/debug.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,19 @@ impl MetachainDebugRPCServer for MetachainDebugRPCModule {
130130
let TxResponse { used_gas, .. } = self
131131
.handler
132132
.core
133-
.call(EthCallArgs {
134-
caller,
135-
to: call.to,
136-
value: call.value.unwrap_or_default(),
137-
data,
138-
gas_limit,
139-
gas_price,
140-
access_list: call.access_list.unwrap_or_default(),
141-
block_number,
142-
})
133+
.call(
134+
EthCallArgs {
135+
caller,
136+
to: call.to,
137+
value: call.value.unwrap_or_default(),
138+
data,
139+
gas_limit,
140+
gas_price,
141+
access_list: call.access_list.unwrap_or_default(),
142+
block_number,
143+
},
144+
None,
145+
)
143146
.map_err(RPCError::EvmError)?;
144147

145148
let used_gas = U256::from(used_gas);

0 commit comments

Comments
 (0)