Skip to content

Commit

Permalink
Merge branch 'master' into v4.0.0-rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
Jouzo authored Aug 18, 2023
2 parents 26a3cd2 + 1b9b434 commit 7946511
Show file tree
Hide file tree
Showing 16 changed files with 730 additions and 559 deletions.
1 change: 1 addition & 0 deletions lib/Cargo.lock

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

1 change: 1 addition & 0 deletions lib/ain-contracts/dst20/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"object":"0x608060405234801562000010575f80fd5b506040516200175a3803806200175a8339818101604052810190620000369190620001eb565b81818160039081620000499190620004a5565b5080600490816200005b9190620004a5565b505050505062000589565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b620000c7826200007f565b810181811067ffffffffffffffff82111715620000e957620000e86200008f565b5b80604052505050565b5f620000fd62000066565b90506200010b8282620000bc565b919050565b5f67ffffffffffffffff8211156200012d576200012c6200008f565b5b62000138826200007f565b9050602081019050919050565b5f5b838110156200016457808201518184015260208101905062000147565b5f8484015250505050565b5f620001856200017f8462000110565b620000f2565b905082815260208101848484011115620001a457620001a36200007b565b5b620001b184828562000145565b509392505050565b5f82601f830112620001d057620001cf62000077565b5b8151620001e28482602086016200016f565b91505092915050565b5f80604083850312156200020457620002036200006f565b5b5f83015167ffffffffffffffff81111562000224576200022362000073565b5b6200023285828601620001b9565b925050602083015167ffffffffffffffff81111562000256576200025562000073565b5b6200026485828601620001b9565b9150509250929050565b5f81519050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f6002820490506001821680620002bd57607f821691505b602082108103620002d357620002d262000278565b5b50919050565b5f819050815f5260205f209050919050565b5f6020601f8301049050919050565b5f82821b905092915050565b5f60088302620003377fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82620002fa565b620003438683620002fa565b95508019841693508086168417925050509392505050565b5f819050919050565b5f819050919050565b5f6200038d6200038762000381846200035b565b62000364565b6200035b565b9050919050565b5f819050919050565b620003a8836200036d565b620003c0620003b78262000394565b84845462000306565b825550505050565b5f90565b620003d6620003c8565b620003e38184846200039d565b505050565b5b818110156200040a57620003fe5f82620003cc565b600181019050620003e9565b5050565b601f82111562000459576200042381620002d9565b6200042e84620002eb565b810160208510156200043e578190505b620004566200044d85620002eb565b830182620003e8565b50505b505050565b5f82821c905092915050565b5f6200047b5f19846008026200045e565b1980831691505092915050565b5f6200049583836200046a565b9150826002028217905092915050565b620004b0826200026e565b67ffffffffffffffff811115620004cc57620004cb6200008f565b5b620004d88254620002a5565b620004e58282856200040e565b5f60209050601f8311600181146200051b575f841562000506578287015190505b62000512858262000488565b86555062000581565b601f1984166200052b86620002d9565b5f5b8281101562000554578489015182556001820191506020850194506020810190506200052d565b8683101562000574578489015162000570601f8916826200046a565b8355505b6001600288020188555050505b505050505050565b6111c380620005975f395ff3fe608060405234801561000f575f80fd5b50600436106100a7575f3560e01c8063395093511161006f578063395093511461016557806370a082311461019557806395d89b41146101c5578063a457c2d7146101e3578063a9059cbb14610213578063dd62ed3e14610243576100a7565b806306fdde03146100ab578063095ea7b3146100c957806318160ddd146100f957806323b872dd14610117578063313ce56714610147575b5f80fd5b6100b3610273565b6040516100c09190610add565b60405180910390f35b6100e360048036038101906100de9190610b8e565b610303565b6040516100f09190610be6565b60405180910390f35b610101610325565b60405161010e9190610c0e565b60405180910390f35b610131600480360381019061012c9190610c27565b61032e565b60405161013e9190610be6565b60405180910390f35b61014f61035c565b60405161015c9190610c92565b60405180910390f35b61017f600480360381019061017a9190610b8e565b610364565b60405161018c9190610be6565b60405180910390f35b6101af60048036038101906101aa9190610cab565b61039a565b6040516101bc9190610c0e565b60405180910390f35b6101cd6103df565b6040516101da9190610add565b60405180910390f35b6101fd60048036038101906101f89190610b8e565b61046f565b60405161020a9190610be6565b60405180910390f35b61022d60048036038101906102289190610b8e565b6104e4565b60405161023a9190610be6565b60405180910390f35b61025d60048036038101906102589190610cd6565b610506565b60405161026a9190610c0e565b60405180910390f35b60606003805461028290610d41565b80601f01602080910402602001604051908101604052809291908181526020018280546102ae90610d41565b80156102f95780601f106102d0576101008083540402835291602001916102f9565b820191905f5260205f20905b8154815290600101906020018083116102dc57829003601f168201915b5050505050905090565b5f8061030d610588565b905061031a81858561058f565b600191505092915050565b5f600254905090565b5f80610338610588565b9050610345858285610752565b6103508585856107dd565b60019150509392505050565b5f6012905090565b5f8061036e610588565b905061038f8185856103808589610506565b61038a9190610d9e565b61058f565b600191505092915050565b5f805f8373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f20549050919050565b6060600480546103ee90610d41565b80601f016020809104026020016040519081016040528092919081815260200182805461041a90610d41565b80156104655780601f1061043c57610100808354040283529160200191610465565b820191905f5260205f20905b81548152906001019060200180831161044857829003601f168201915b5050505050905090565b5f80610479610588565b90505f6104868286610506565b9050838110156104cb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104c290610e41565b60405180910390fd5b6104d8828686840361058f565b60019250505092915050565b5f806104ee610588565b90506104fb8185856107dd565b600191505092915050565b5f60015f8473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f8373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f2054905092915050565b5f33905090565b5f73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16036105fd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105f490610ecf565b60405180910390fd5b5f73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff160361066b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161066290610f5d565b60405180910390fd5b8060015f8573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f8473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f20819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040516107459190610c0e565b60405180910390a3505050565b5f61075d8484610506565b90507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81146107d757818110156107c9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107c090610fc5565b60405180910390fd5b6107d6848484840361058f565b5b50505050565b5f73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff160361084b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161084290611053565b60405180910390fd5b5f73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16036108b9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108b0906110e1565b60405180910390fd5b6108c4838383610a49565b5f805f8573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f2054905081811015610947576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161093e9061116f565b60405180910390fd5b8181035f808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f2081905550815f808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f82825401925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051610a309190610c0e565b60405180910390a3610a43848484610a4e565b50505050565b505050565b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b83811015610a8a578082015181840152602081019050610a6f565b5f8484015250505050565b5f601f19601f8301169050919050565b5f610aaf82610a53565b610ab98185610a5d565b9350610ac9818560208601610a6d565b610ad281610a95565b840191505092915050565b5f6020820190508181035f830152610af58184610aa5565b905092915050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f610b2a82610b01565b9050919050565b610b3a81610b20565b8114610b44575f80fd5b50565b5f81359050610b5581610b31565b92915050565b5f819050919050565b610b6d81610b5b565b8114610b77575f80fd5b50565b5f81359050610b8881610b64565b92915050565b5f8060408385031215610ba457610ba3610afd565b5b5f610bb185828601610b47565b9250506020610bc285828601610b7a565b9150509250929050565b5f8115159050919050565b610be081610bcc565b82525050565b5f602082019050610bf95f830184610bd7565b92915050565b610c0881610b5b565b82525050565b5f602082019050610c215f830184610bff565b92915050565b5f805f60608486031215610c3e57610c3d610afd565b5b5f610c4b86828701610b47565b9350506020610c5c86828701610b47565b9250506040610c6d86828701610b7a565b9150509250925092565b5f60ff82169050919050565b610c8c81610c77565b82525050565b5f602082019050610ca55f830184610c83565b92915050565b5f60208284031215610cc057610cbf610afd565b5b5f610ccd84828501610b47565b91505092915050565b5f8060408385031215610cec57610ceb610afd565b5b5f610cf985828601610b47565b9250506020610d0a85828601610b47565b9150509250929050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f6002820490506001821680610d5857607f821691505b602082108103610d6b57610d6a610d14565b5b50919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f610da882610b5b565b9150610db383610b5b565b9250828201905080821115610dcb57610dca610d71565b5b92915050565b7f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f775f8201527f207a65726f000000000000000000000000000000000000000000000000000000602082015250565b5f610e2b602583610a5d565b9150610e3682610dd1565b604082019050919050565b5f6020820190508181035f830152610e5881610e1f565b9050919050565b7f45524332303a20617070726f76652066726f6d20746865207a65726f206164645f8201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b5f610eb9602483610a5d565b9150610ec482610e5f565b604082019050919050565b5f6020820190508181035f830152610ee681610ead565b9050919050565b7f45524332303a20617070726f766520746f20746865207a65726f2061646472655f8201527f7373000000000000000000000000000000000000000000000000000000000000602082015250565b5f610f47602283610a5d565b9150610f5282610eed565b604082019050919050565b5f6020820190508181035f830152610f7481610f3b565b9050919050565b7f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000005f82015250565b5f610faf601d83610a5d565b9150610fba82610f7b565b602082019050919050565b5f6020820190508181035f830152610fdc81610fa3565b9050919050565b7f45524332303a207472616e736665722066726f6d20746865207a65726f2061645f8201527f6472657373000000000000000000000000000000000000000000000000000000602082015250565b5f61103d602583610a5d565b915061104882610fe3565b604082019050919050565b5f6020820190508181035f83015261106a81611031565b9050919050565b7f45524332303a207472616e7366657220746f20746865207a65726f20616464725f8201527f6573730000000000000000000000000000000000000000000000000000000000602082015250565b5f6110cb602383610a5d565b91506110d682611071565b604082019050919050565b5f6020820190508181035f8301526110f8816110bf565b9050919050565b7f45524332303a207472616e7366657220616d6f756e74206578636565647320625f8201527f616c616e63650000000000000000000000000000000000000000000000000000602082015250565b5f611159602683610a5d565b9150611164826110ff565b604082019050919050565b5f6020820190508181035f8301526111868161114d565b905091905056fea26469706673582212203aa41342448711bc720579d3c6d118ea09749c4045d7f6250a490a827d38de1e64736f6c63430008140033000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000005445354323000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000054453543230000000000000000000000000000000000000000000000000000000"}
4 changes: 4 additions & 0 deletions lib/ain-contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ pub fn get_dst20_bytecode() -> Result<Vec<u8>> {
get_bytecode(include_str!("../dst20/output/bytecode.json"))
}

pub fn get_dst20_input() -> Result<Vec<u8>> {
get_bytecode(include_str!("../dst20/input.json"))
}

pub fn get_system_reserved_bytecode() -> Result<Vec<u8>> {
get_bytecode(include_str!("../system_reserved/output/bytecode.json"))
}
Expand Down
3 changes: 3 additions & 0 deletions lib/ain-evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ num = { version = "0.4", default-features = false, features = ["alloc"] }
ripemd = { version = "0.1", default-features = false }
substrate-bn = "0.6.0"

# Database dependencies
rocksdb = { version = "0.20.1", default-features = false }

[dev-dependencies]
tempdir = "0.3.7"
once_cell = "1.17.1"
152 changes: 76 additions & 76 deletions lib/ain-evm/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,80 +321,80 @@ impl BlockService {

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_base_fee_equal() {
let block = BlockService::new(Arc::new(Storage::new())).unwrap();
assert_eq!(
U256::from(20_000_000_000u64),
block.base_fee_calculation(
15_000_000,
15_000_000,
U256::from(20_000_000_000u64),
U256::from(8),
U256::from(10_000_000_000u64)
)
)
}

#[test]
fn test_base_fee_max_increase() {
let block = BlockService::new(Arc::new(Storage::new())).unwrap();
assert_eq!(
U256::from(22_500_000_000u64), // should increase by 12.5%
block.base_fee_calculation(
30_000_000,
15_000_000,
U256::from(20_000_000_000u64),
U256::from(8),
U256::from(10_000_000_000u64)
)
)
}

#[test]
fn test_base_fee_increase() {
let block = BlockService::new(Arc::new(Storage::new())).unwrap();
assert_eq!(
U256::from(20_833_333_333u64), // should increase by ~4.15%
block.base_fee_calculation(
20_000_000,
15_000_000,
U256::from(20_000_000_000u64),
U256::from(8),
U256::from(10_000_000_000u64)
)
)
}

#[test]
fn test_base_fee_max_decrease() {
let block = BlockService::new(Arc::new(Storage::new())).unwrap();
assert_eq!(
U256::from(17_500_000_000u64), // should decrease by 12.5%
block.base_fee_calculation(
0,
15_000_000,
U256::from(20_000_000_000u64),
U256::from(8),
U256::from(10_000_000_000u64)
)
)
}

#[test]
fn test_base_fee_decrease() {
let block = BlockService::new(Arc::new(Storage::new())).unwrap();
assert_eq!(
U256::from(19_166_666_667u64), // should increase by ~4.15%
block.base_fee_calculation(
10_000_000,
15_000_000,
U256::from(20_000_000_000u64),
U256::from(8),
U256::from(10_000_000_000u64)
)
)
}
// use super::*;

// #[test]
// fn test_base_fee_equal() {
// let block = BlockService::new(Arc::new(Storage::new()?)).unwrap();
// assert_eq!(
// U256::from(20_000_000_000u64),
// block.base_fee_calculation(
// 15_000_000,
// 15_000_000,
// U256::from(20_000_000_000u64),
// U256::from(8),
// U256::from(10_000_000_000u64)
// )
// )
// }

// #[test]
// fn test_base_fee_max_increase() {
// let block = BlockService::new(Arc::new(Storage::new()?)).unwrap();
// assert_eq!(
// U256::from(22_500_000_000u64), // should increase by 12.5%
// block.base_fee_calculation(
// 30_000_000,
// 15_000_000,
// U256::from(20_000_000_000u64),
// U256::from(8),
// U256::from(10_000_000_000u64)
// )
// )
// }

// #[test]
// fn test_base_fee_increase() {
// let block = BlockService::new(Arc::new(Storage::new()?)).unwrap();
// assert_eq!(
// U256::from(20_833_333_333u64), // should increase by ~4.15%
// block.base_fee_calculation(
// 20_000_000,
// 15_000_000,
// U256::from(20_000_000_000u64),
// U256::from(8),
// U256::from(10_000_000_000u64)
// )
// )
// }

// #[test]
// fn test_base_fee_max_decrease() {
// let block = BlockService::new(Arc::new(Storage::new()?)).unwrap();
// assert_eq!(
// U256::from(17_500_000_000u64), // should decrease by 12.5%
// block.base_fee_calculation(
// 0,
// 15_000_000,
// U256::from(20_000_000_000u64),
// U256::from(8),
// U256::from(10_000_000_000u64)
// )
// )
// }

// #[test]
// fn test_base_fee_decrease() {
// let block = BlockService::new(Arc::new(Storage::new()?)).unwrap();
// assert_eq!(
// U256::from(19_166_666_667u64), // should increase by ~4.15%
// block.base_fee_calculation(
// 10_000_000,
// 15_000_000,
// U256::from(20_000_000_000u64),
// U256::from(8),
// U256::from(10_000_000_000u64)
// )
// )
// }
}
28 changes: 15 additions & 13 deletions lib/ain-evm/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,16 @@ pub struct ValidateTxInfo {
pub used_gas: u64,
}

fn init_vsdb() {
fn init_vsdb(path: PathBuf) {
debug!(target: "vsdb", "Initializating VSDB");
let datadir = ain_cpp_imports::get_datadir();
let path = PathBuf::from(datadir).join("evm");
if !path.exists() {
std::fs::create_dir(&path).expect("Error creating `evm` dir");
}
let vsdb_dir_path = path.join(".vsdb");
vsdb_set_base_dir(&vsdb_dir_path).expect("Could not update vsdb base dir");
debug!(target: "vsdb", "VSDB directory : {}", vsdb_dir_path.display());
}

impl EVMCoreService {
pub fn restore(storage: Arc<Storage>) -> Self {
init_vsdb();
pub fn restore(storage: Arc<Storage>, path: PathBuf) -> Self {
init_vsdb(path);

Self {
tx_queues: Arc::new(TransactionQueueMap::new()),
Expand All @@ -76,17 +71,24 @@ impl EVMCoreService {
}
}

pub fn new_from_json(storage: Arc<Storage>, path: PathBuf) -> Result<Self> {
debug!("Loading genesis state from {}", path.display());
init_vsdb();
pub fn new_from_json(
storage: Arc<Storage>,
genesis_path: PathBuf,
evm_datadir: PathBuf,
) -> Result<Self> {
debug!("Loading genesis state from {}", genesis_path.display());
init_vsdb(evm_datadir);

let handler = Self {
tx_queues: Arc::new(TransactionQueueMap::new()),
trie_store: Arc::new(TrieDBStore::new()),
storage: Arc::clone(&storage),
};
let (state_root, genesis) =
TrieDBStore::genesis_state_root_from_json(&handler.trie_store, &handler.storage, path)?;
let (state_root, genesis) = TrieDBStore::genesis_state_root_from_json(
&handler.trie_store,
&handler.storage,
genesis_path,
)?;

let gas_limit = storage.get_attributes_or_default()?.block_gas_limit;
let block: Block<TransactionV2> = Block::new(
Expand Down
Loading

0 comments on commit 7946511

Please sign in to comment.