Skip to content

Commit

Permalink
Merge branch 'develop' into develop_eip1559
Browse files Browse the repository at this point in the history
  • Loading branch information
HarryLiIsMe authored Feb 6, 2023
2 parents cc90645 + 3dd406c commit 9aa680d
Show file tree
Hide file tree
Showing 41 changed files with 698 additions and 773 deletions.
9 changes: 5 additions & 4 deletions src/components/abciapp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ ruc = { version = "1.0.5", default-features = false, features = ["compact"] }
module-evm = { path = "../contracts/modules/evm"}
ethereum-types = { version = "0.13.1", default-features = false }

noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" }
noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" }
noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" }
noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" }

abci = { git = "https://github.com/FindoraNetwork/tendermint-abci", tag = "0.7.5" }
config = { path = "../config"}
Expand All @@ -58,7 +58,8 @@ tempfile = "3.1.0"
baseapp = { path = "../contracts/baseapp" }
fc-rpc = { path = "../contracts/rpc" }
fp-storage = { path = "../contracts/primitives/storage" }
fp-utils = { path = "../contracts/primitives/utils" }
fp-types = {path = "../contracts/primitives/types"}
fp-utils = {path = "../contracts/primitives/utils" }


enterprise-web3 = { path = "../contracts/primitives/enterprise-web3", optional = true }
Expand All @@ -75,5 +76,5 @@ vergen = "=3.1.0"
[features]
default = ["diskcache"]
diskcache = ["ledger/diskcache"]
debug_env = ["ledger/debug_env", "config/debug_env"]
debug_env = ["ledger/debug_env", "config/debug_env", "baseapp/debug_env"]
web3_service = ["enterprise-web3", "baseapp/web3_service"]
108 changes: 80 additions & 28 deletions src/components/abciapp/src/abci/server/callback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use {
staking::KEEP_HIST,
store::api_cache,
},
module_evm::utils::{deposit_asset_event_topic_str, parse_deposit_asset_event},
parking_lot::{Mutex, RwLock},
protobuf::RepeatedField,
ruc::*,
Expand Down Expand Up @@ -374,30 +375,85 @@ pub fn deliver_tx(
}
let mut resp = s.account_base_app.write().deliver_tx(req);

if td_height > CFG.checkpoint.fix_prism_mint_pay && 0 == resp.code {
let mut la = s.la.write();
let mut laa = la.get_committed_state().write();
if let Some(tx) = staking::system_prism_mint_pay(
&mut laa,
&mut s.account_base_app.write(),
) {
drop(laa);
if la.cache_transaction(tx).is_ok() {
return resp;
if td_height > CFG.checkpoint.prismxx_inital_height && 0 == resp.code {
let deposit_asset_topic = deposit_asset_event_topic_str();

for evt in resp.events.iter() {
if evt.field_type == *"ethereum_ContractLog" {
let mut bridge_contract_found = false;
let mut deposit_asset_foud = false;

for pair in evt.attributes.iter() {
let key = String::from_utf8(pair.key.clone())
.unwrap_or_default();
if key == *"address" {
let addr = String::from_utf8(pair.value.clone())
.unwrap_or_default();
if addr
== CFG
.checkpoint
.prism_bridge_address
.to_lowercase()
{
bridge_contract_found = true
}
}
if key == *"topics" {
let topic = String::from_utf8(pair.value.clone())
.unwrap_or_default();
if topic == deposit_asset_topic {
deposit_asset_foud = true
}
}
if key == *"data"
&& bridge_contract_found
&& deposit_asset_foud
{
let data = String::from_utf8(pair.value.clone())
.unwrap_or_default();

let data_vec = serde_json::from_str(&data).unwrap();

let deposit_asset =
parse_deposit_asset_event(data_vec);

match deposit_asset {
Ok(deposit) => {
let mut la = s.la.write();
let mut laa =
la.get_committed_state().write();
if let Some(tx) =
staking::system_prism_mint_pay(
&mut laa, deposit,
)
{
drop(laa);
if la.cache_transaction(tx).is_ok() {
return resp;
}
resp.code = 1;
s.account_base_app
.read()
.deliver_state
.state
.write()
.discard_session();
s.account_base_app
.read()
.deliver_state
.db
.write()
.discard_session();
}
}
Err(e) => {
resp.code = 1;
resp.log = e.to_string();
}
}
}
}
}
resp.code = 1;
s.account_base_app
.read()
.deliver_state
.state
.write()
.discard_session();
s.account_base_app
.read()
.deliver_state
.db
.write()
.discard_session();
}
}
resp
Expand Down Expand Up @@ -434,11 +490,7 @@ pub fn end_block(
// mint coinbase, cache system transactions to ledger
{
let mut laa = la.get_committed_state().write();
if let Some(tx) = staking::system_mint_pay(
td_height,
&mut laa,
&mut s.account_base_app.write(),
) {
if let Some(tx) = staking::system_mint_pay(td_height, &mut laa) {
drop(laa);
// this unwrap should be safe
la.cache_transaction(tx).unwrap();
Expand Down
8 changes: 6 additions & 2 deletions src/components/abciapp/src/abci/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,17 @@ impl ABCISubmissionServer {
None => {
pnk!(AccountBaseAPP::new(
tempfile::tempdir().unwrap().path(),
CFG.disable_eth_empty_blocks
CFG.disable_eth_empty_blocks,
CFG.arc_history,
CFG.arc_fresh
))
}
Some(basedir) => {
pnk!(AccountBaseAPP::new(
Path::new(basedir),
CFG.disable_eth_empty_blocks
CFG.disable_eth_empty_blocks,
CFG.arc_history,
CFG.arc_fresh
))
}
};
Expand Down
137 changes: 37 additions & 100 deletions src/components/abciapp/src/abci/staking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ mod test;
use {
crate::abci::server::callback::TENDERMINT_BLOCK_HEIGHT,
abci::{Evidence, Header, LastCommitInfo, PubKey, ValidatorUpdate},
baseapp::BaseApp as AccountBaseApp,
config::abci::global_cfg::CFG,
fp_types::actions::xhub::NonConfidentialOutput,
lazy_static::lazy_static,
ledger::{
data_model::{
Expand Down Expand Up @@ -285,120 +285,57 @@ fn system_governance(staking: &mut Staking, bz: &ByzantineInfo) -> Result<()> {
/// Pay for freed 'Delegations' and 'FraDistributions'.
pub fn system_prism_mint_pay(
la: &mut LedgerState,
account_base_app: &mut AccountBaseApp,
mint: NonConfidentialOutput,
) -> Option<Transaction> {
let mut mints = Vec::new();

if let Some(account_mint) = account_base_app.consume_mint() {
for mint in account_mint {
if mint.asset != ASSET_TYPE_FRA {
let atc = AssetTypeCode { val: mint.asset };
let at = if let Some(mut at) = la.get_asset_type(&atc) {
at.properties.issuer = IssuerPublicKey {
key: *BLACK_HOLE_PUBKEY_STAKING,
};
if mint.max_supply != 0 {
at.properties.asset_rules.max_units = Some(mint.max_supply);
}
at.properties.asset_rules.decimals = mint.decimal;
at
} else {
let mut at = AssetType::default();
at.properties.issuer = IssuerPublicKey {
key: *BLACK_HOLE_PUBKEY_STAKING,
};
if mint.asset != ASSET_TYPE_FRA {
let atc = AssetTypeCode { val: mint.asset };
let at = if let Some(mut at) = la.get_asset_type(&atc) {
at.properties.issuer = IssuerPublicKey {
key: *BLACK_HOLE_PUBKEY_STAKING,
};
if mint.max_supply != 0 {
at.properties.asset_rules.max_units = Some(mint.max_supply);
}
at.properties.asset_rules.decimals = mint.decimal;
at
} else {
let mut at = AssetType::default();
at.properties.issuer = IssuerPublicKey {
key: *BLACK_HOLE_PUBKEY_STAKING,
};

if mint.max_supply != 0 {
at.properties.asset_rules.max_units = Some(mint.max_supply);
}
at.properties.asset_rules.decimals = mint.decimal;
if mint.max_supply != 0 {
at.properties.asset_rules.max_units = Some(mint.max_supply);
}
at.properties.asset_rules.decimals = mint.decimal;

at.properties.code = AssetTypeCode { val: mint.asset };
at.properties.code = AssetTypeCode { val: mint.asset };

at
};
at
};

la.insert_asset_type(atc, at);
}
la.insert_asset_type(atc, at);
}

let mint_entry = MintEntry::new(
MintKind::Other,
mint.target,
None,
mint.amount,
mint.asset,
);
let mint_entry =
MintEntry::new(MintKind::Other, mint.target, None, mint.amount, mint.asset);

mints.push(mint_entry);
}
}
mints.push(mint_entry);

if mints.is_empty() {
None
} else {
let mint_ops =
Operation::MintFra(MintFraOps::new(la.get_staking().cur_height(), mints));
Some(Transaction::from_operation_coinbase_mint(
mint_ops,
la.get_state_commitment().1,
))
}
let mint_ops =
Operation::MintFra(MintFraOps::new(la.get_staking().cur_height(), mints));
Some(Transaction::from_operation_coinbase_mint(
mint_ops,
la.get_state_commitment().1,
))
}

/// Pay for freed 'Delegations' and 'FraDistributions'.
pub fn system_mint_pay(
td_height: i64,
la: &mut LedgerState,
account_base_app: &mut AccountBaseApp,
) -> Option<Transaction> {
pub fn system_mint_pay(td_height: i64, la: &mut LedgerState) -> Option<Transaction> {
let mut mints = Vec::new();

if td_height <= CFG.checkpoint.fix_prism_mint_pay {
if let Some(account_mint) = account_base_app.consume_mint() {
for mint in account_mint {
if mint.asset != ASSET_TYPE_FRA {
let atc = AssetTypeCode { val: mint.asset };
let at = if let Some(mut at) = la.get_asset_type(&atc) {
at.properties.issuer = IssuerPublicKey {
key: *BLACK_HOLE_PUBKEY_STAKING,
};

if mint.max_supply != 0 {
at.properties.asset_rules.max_units = Some(mint.max_supply);
}

at
} else {
let mut at = AssetType::default();
at.properties.issuer = IssuerPublicKey {
key: *BLACK_HOLE_PUBKEY_STAKING,
};

if mint.max_supply != 0 {
at.properties.asset_rules.max_units = Some(mint.max_supply);
}

at.properties.code = AssetTypeCode { val: mint.asset };

at
};

la.insert_asset_type(atc, at);
}

let mint_entry = MintEntry::new(
MintKind::Other,
mint.target,
None,
mint.amount,
mint.asset,
);

mints.push(mint_entry);
}
}
}

let staking = la.get_staking();
let mut limit = staking.coinbase_balance() as i128;

Expand Down
3 changes: 1 addition & 2 deletions src/components/abciapp/src/bins/abcid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use {

fn main() {
globutils::logging::init_logging(None);

tracing::info!(concat!(
tracing::info!(target: "abciapp", concat!(
"Build: ",
env!("VERGEN_SHA"),
" ",
Expand Down
12 changes: 11 additions & 1 deletion src/components/abciapp/src/bins/findorad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ fn node_command() -> Result<()> {
.checkpoint_file
.clone()
.unwrap_or_else(|| String::from("./checkpoint.toml"));
let arc_history_arg = {
if let Some(interval) = CFG.arc_history.1 {
format!("{},{}", CFG.arc_history.0, interval)
} else {
format!("{}", CFG.arc_history.0)
}
};

abcid
.arg("--submission-service-port")
Expand All @@ -58,7 +65,9 @@ fn node_command() -> Result<()> {
.arg("--checkpoint-file")
.arg(&checkpoint_file)
.arg("--ledger-dir")
.arg(&CFG.ledger_dir);
.arg(&CFG.ledger_dir)
.arg("--arc-history")
.arg(&arc_history_arg);

for (condition, action) in [
(CFG.enable_query_service, "--enable-query-service"),
Expand All @@ -67,6 +76,7 @@ fn node_command() -> Result<()> {
(CFG.enable_snapshot, "--enable-snapshot"),
(CFG.snapshot_list, "--snapshot-list"),
(CFG.snapshot_rollback, "--snapshot-rollback"),
(CFG.arc_fresh, "--arc-fresh"),
] {
if condition {
abcid.arg(action);
Expand Down
Loading

0 comments on commit 9aa680d

Please sign in to comment.