Skip to content
This repository was archived by the owner on Jun 30, 2023. It is now read-only.

Commit 2aeb6ed

Browse files
committed
fix mining epoch block issues;
fix ci warning issues; fix unit test err;
1 parent fa3ec80 commit 2aeb6ed

39 files changed

+308
-425
lines changed

Cargo.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ ethereum-jsonrpc = { git = "https://github.com/vorot93/ethereum-jsonrpc", featur
5252
] }
5353
ethnum = { version = "1", features = ["eio", "rlp"] }
5454
ethsecp256k1 = { package = "eth-secp256k1", git = "https://github.com/paritytech/rust-secp256k1", rev = "ccc06e7480148b723eb44ac56cf4d20eec380b6f" }
55-
ethabi = { git = "https://github.com/setunapo/ethabi", package = "ethabi", branch = "akula_ethereum_type_v0.14.0" }
56-
ethabi-contract = { git = "https://github.com/setunapo/ethabi", package = "ethabi-contract", branch = "akula_ethereum_type_v0.14.0" }
57-
ethabi-derive = { git = "https://github.com/setunapo/ethabi", package = "ethabi-derive", branch = "akula_ethereum_type_v0.14.0" }
55+
ethabi = { git = "https://github.com/rust-ethereum/ethabi", tag = "v18.0.0", package = "ethabi" }
56+
ethabi-contract = { git = "https://github.com/rust-ethereum/ethabi", tag = "v18.0.0", package = "ethabi-contract" }
57+
ethabi-derive = { git = "https://github.com/rust-ethereum/ethabi", tag = "v18.0.0", package = "ethabi-derive" }
5858
fastrlp = { version = "0.2", features = [
5959
"derive",
6060
"ethbloom",

bin/akula.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::devp2p::Swarm;
21
use akula::{
32
akula_tracing::{self, Component},
43
binutil::AkulaDataDir,
@@ -13,7 +12,6 @@ use akula::{
1312
net::NetApiServerImpl, otterscan::OtterscanApiServerImpl, parity::ParityApiServerImpl,
1413
trace::TraceApiServerImpl, web3::Web3ApiServerImpl,
1514
},
16-
sentry::*,
1715
stagedsync,
1816
stages::{stage_util::IndexParams, *},
1917
version_string,
@@ -26,12 +24,8 @@ use ethereum_jsonrpc::{
2624
TraceApiServer, Web3ApiServer,
2725
};
2826
use expanded_pathbuf::ExpandedPathBuf;
29-
use futures::executor::block_on;
3027
use http::Uri;
31-
use jsonrpsee::{
32-
core::server::rpc_module::Methods,
33-
server::ServerBuilder
34-
};
28+
use jsonrpsee::{core::server::rpc_module::Methods, server::ServerBuilder};
3529
use num_bigint::BigInt;
3630
use secp256k1::SecretKey;
3731
use std::{
@@ -561,9 +555,9 @@ fn main() -> anyhow::Result<()> {
561555
consensus_config.authorize(ECDSASigner::from_secret(&opt.mine_secretkey.unwrap()[..]));
562556
let mining_config = Arc::new(Mutex::new(MiningConfig {
563557
enabled: true,
564-
ether_base: opt.mine_etherbase.unwrap().clone(),
565-
secret_key: opt.mine_secretkey.unwrap().clone(),
566-
extra_data: opt.mine_extradata.map(Bytes::from).clone(),
558+
ether_base: opt.mine_etherbase.unwrap(),
559+
secret_key: opt.mine_secretkey.unwrap(),
560+
extra_data: opt.mine_extradata.map(Bytes::from),
567561
consensus: consensus_config,
568562
dao_fork_block: Some(BigInt::new(num_bigint::Sign::Plus, vec![])),
569563
dao_fork_support: false,
@@ -604,9 +598,9 @@ fn main() -> anyhow::Result<()> {
604598

605599
staged_mining.push(
606600
MiningFinishBlock {
607-
mining_status: mining_status.clone(),
608-
mining_block: mining_block.clone(),
609-
mining_config: mining_config.clone(),
601+
mining_status,
602+
mining_block,
603+
mining_config,
610604
chain_spec: chainspec.clone(),
611605
node: node.clone(),
612606
},

src/consensus/clique/clique_snapshot.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::{
22
consensus::{clique::*, SnapDB},
3-
kv::{mdbx::*, tables, MdbxWithDirHandle},
4-
p2p::types::GetBlockHeadersParams,
3+
kv::{mdbx::*, tables},
54
HeaderReader,
65
};
76
use ethereum_types::Address;
@@ -74,8 +73,7 @@ impl CliqueSnapshot {
7473
if snap
7574
.recent_proposers
7675
.iter()
77-
.find(|(_, addr)| **addr == proposer)
78-
.is_some()
76+
.any(|(_, addr)| *addr == proposer)
7977
{
8078
return Err(CliqueError::SignerOverLimit { signer: proposer }.into());
8179
}

src/consensus/clique/clique_util.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{consensus::*, crypto};
2-
use bytes::{Buf, Bytes};
2+
use bytes::Bytes;
33
use ethereum_types::{Address, Public, H256};
44
use lazy_static::lazy_static;
55
use lru_cache::LruCache;
@@ -68,7 +68,7 @@ pub fn parse_epoch_validators(bytes: &[u8]) -> Result<Vec<Address>, DuoError> {
6868
return Err(ParliaError::WrongHeaderExtraSignersLen {
6969
expected: 0,
7070
got: bytes.len() % ADDRESS_LENGTH,
71-
msg: format!("parse_epoch_validators got wrong len!"),
71+
msg: "parse_epoch_validators got wrong len!".to_string(),
7272
}
7373
.into());
7474
}
@@ -113,22 +113,17 @@ pub fn recover_creator(header: &BlockHeader, chain_id: ChainId) -> Result<Addres
113113
let address_slice = &Keccak256::digest(&public.serialize_uncompressed()[1..])[12..];
114114

115115
let creator = Address::from_slice(address_slice);
116-
cache.insert(header.hash(), creator.clone());
116+
cache.insert(header.hash(), creator);
117117
Ok(creator)
118118
}
119119

120120
/// check tx is similar
121121
pub fn is_similar_tx(actual: &Message, expect: &Message) -> bool {
122-
if actual.max_fee_per_gas() == expect.max_fee_per_gas()
122+
actual.max_fee_per_gas() == expect.max_fee_per_gas()
123123
&& actual.max_fee_per_gas() == expect.max_fee_per_gas()
124124
&& actual.value() == expect.value()
125125
&& actual.input() == expect.input()
126126
&& actual.action() == expect.action()
127-
{
128-
true
129-
} else {
130-
false
131-
}
132127
}
133128

134129
/// find header.block_number - count, block header

src/consensus/clique/mod.rs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,29 @@ pub mod clique_util;
66
use crate::{
77
consensus::{
88
clique_snapshot::CliqueSnapshot, fork_choice_graph::ForkChoiceGraph, state::CliqueBlock,
9-
CliqueError, Consensus, ConsensusEngineBase, ConsensusState, DuoError,
10-
DuoError::Validation, FinalizationChange, ForkChoiceMode, ValidationError,
9+
CliqueError, Consensus, ConsensusEngineBase, ConsensusState, DuoError, FinalizationChange,
10+
ForkChoiceMode, ValidationError,
1111
},
1212
kv::{mdbx::*, tables},
1313
models::{
14-
Block, BlockHeader, BlockNumber, ChainConfig, ChainId, ChainSpec, MessageWithSender,
15-
Receipt, Seal, EMPTY_LIST_HASH,
14+
Block, BlockHeader, BlockNumber, ChainConfig, ChainId, ChainSpec, MessageWithSender, Seal,
15+
EMPTY_LIST_HASH,
1616
},
17-
state::{IntraBlockState, StateReader},
17+
state::StateReader,
1818
BlockReader, HeaderReader,
1919
};
2020
use anyhow::bail;
21-
use byte_unit::Byte;
2221
use bytes::Bytes;
23-
use cipher::typenum::private::IsEqualPrivate;
24-
//use ethabi::Bytes;
25-
use ethereum_types::{Address, H256, H64};
22+
use ethereum_types::{Address, H256};
2623
use lru_cache::LruCache;
2724
use mdbx::{EnvironmentKind, TransactionKind};
2825
use parking_lot::{Mutex, RwLock};
29-
use rlp::RlpStream;
3026
use secp256k1::{
3127
ecdsa::{RecoverableSignature, RecoveryId},
3228
Message as SecpMessage, SECP256K1,
3329
};
3430
use sha3::{Digest, Keccak256};
35-
use std::{
36-
io::Read,
37-
sync::Arc,
38-
time::{Duration, SystemTime},
39-
unreachable,
40-
};
41-
use tendermint::signature::Signer;
42-
use tracing::{debug, info};
43-
use trust_dns_resolver::proto::{serialize::binary::BinEncodable, Time};
31+
use std::{sync::Arc, time::Duration, unreachable};
4432

4533
const EXTRA_VANITY: usize = 32;
4634
const EXTRA_SEAL: usize = 65;

src/consensus/mod.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,28 @@ pub mod parlia;
88
use self::fork_choice_graph::ForkChoiceGraph;
99
pub use self::{base::*, beacon::*, blockchain::*, clique::*, parlia::*};
1010
use crate::{
11-
consensus::vote::VotePool,
1211
crypto::signer::ECDSASigner,
1312
kv::{mdbx::*, tables, MdbxWithDirHandle},
1413
models::*,
14+
p2p::node::Node,
1515
state::{IntraBlockState, StateReader},
16-
BlockReader, HeaderReader,
16+
BlockReader, Buffer, HeaderReader,
1717
};
1818
use anyhow::{anyhow, bail};
19-
use arrayvec::ArrayVec;
2019
use derive_more::{Display, From};
21-
use ethnum::u256;
2220
use fastrlp::DecodeError;
2321
use mdbx::{EnvironmentKind, TransactionKind};
2422
use milagro_bls::AmclError;
2523
use parking_lot::Mutex;
2624
use std::{
2725
collections::BTreeSet,
28-
fmt::{Debug, Display, Formatter},
26+
fmt::{Debug, Display},
2927
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
3028
sync::Arc,
3129
time::SystemTimeError,
3230
};
3331
use tokio::sync::watch;
3432
use tracing::*;
35-
use crate::p2p::node::Node;
3633

3734
#[derive(Debug)]
3835
pub enum FinalizationChange {
@@ -85,6 +82,15 @@ impl ConsensusNewBlockState {
8582
_ => ConsensusNewBlockState::Stateless,
8683
})
8784
}
85+
pub(crate) fn handle_with_txn<E: EnvironmentKind>(
86+
chain_spec: &ChainSpec,
87+
header: &BlockHeader,
88+
tx: &MdbxTransaction<'_, RW, E>,
89+
) -> anyhow::Result<ConsensusNewBlockState> {
90+
let mut state = Buffer::new(tx, None);
91+
let mut state = IntraBlockState::new(&mut state);
92+
ConsensusNewBlockState::handle(chain_spec, header, &mut state)
93+
}
8894
}
8995

9096
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -678,21 +684,19 @@ impl Default for InitialParams {
678684
pub fn pre_validate_transaction(
679685
txn: &Message,
680686
canonical_chain_id: ChainId,
681-
_base_fee_per_gas: Option<U256>,
687+
base_fee_per_gas: Option<U256>,
682688
) -> Result<(), ValidationError> {
683689
if let Some(chain_id) = txn.chain_id() {
684690
if chain_id != canonical_chain_id {
685691
return Err(ValidationError::WrongChainId);
686692
}
687693
}
688694

689-
// TODO need pass in system transaction
690-
// info!("tx {:?} base fee {:?}, tx {} max1 {} max2 {}", txn.hash(), base_fee_per_gas, txn.max_fee_per_gas(), txn.max_priority_fee_per_gas(), txn.max_fee_per_gas());
691-
// if let Some(base_fee_per_gas) = base_fee_per_gas {
692-
// if txn.max_fee_per_gas() < base_fee_per_gas {
693-
// return Err(ValidationError::MaxFeeLessThanBase);
694-
// }
695-
// }
695+
if let Some(base_fee_per_gas) = base_fee_per_gas {
696+
if txn.max_fee_per_gas() < base_fee_per_gas {
697+
return Err(ValidationError::MaxFeeLessThanBase);
698+
}
699+
}
696700

697701
// https://github.com/ethereum/EIPs/pull/3594
698702
if txn.max_priority_fee_per_gas() > txn.max_fee_per_gas() {

src/consensus/parlia/contract_upgrade.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use lazy_static::lazy_static;
99
use rustc_hex::FromHex;
1010
use std::{collections::HashMap, str::FromStr};
1111

12-
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
12+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd)]
1313
pub struct UpgradeConfig {
1414
pub contract_addr: &'static str,
1515
pub code: &'static str,
@@ -88,7 +88,7 @@ where
8888
}
8989

9090
pub fn apply_system_contract_upgrade<'r, S>(
91-
upgrade: &Vec<UpgradeConfig>,
91+
upgrade: &[UpgradeConfig],
9292
statedb: &mut IntraBlockState<'r, S>,
9393
) -> anyhow::Result<(), DuoError>
9494
where

0 commit comments

Comments
 (0)