Skip to content

Commit

Permalink
fix evm findora_tx hash (#1015)
Browse files Browse the repository at this point in the history
* fix evm findora_tx hash

* add event

---------

Co-authored-by: shaorongqiang <[email protected]>
  • Loading branch information
shaorongqiang and shaorongqiang authored Oct 10, 2023
1 parent 6f9f37e commit 300d1cc
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 29 deletions.
39 changes: 27 additions & 12 deletions src/components/abciapp/src/abci/server/callback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ use {
},
},
abci::{
CheckTxType, RequestBeginBlock, RequestCheckTx, RequestCommit, RequestDeliverTx,
RequestEndBlock, RequestInfo, RequestInitChain, RequestQuery,
CheckTxType, Event, Pair, RequestBeginBlock, RequestCheckTx, RequestCommit,
RequestDeliverTx, RequestEndBlock, RequestInfo, RequestInitChain, RequestQuery,
ResponseBeginBlock, ResponseCheckTx, ResponseCommit, ResponseDeliverTx,
ResponseEndBlock, ResponseInfo, ResponseInitChain, ResponseQuery,
},
config::abci::global_cfg::CFG,
cryptohash::sha256,
enterprise_web3::{
Setter, ALLOWANCES, BALANCE_MAP, BLOCK, CODE_MAP, NONCE_MAP, RECEIPTS,
REDIS_CLIENT, STATE_UPDATE_LIST, TOTAL_ISSUANCE, TXS, WEB3_SERVICE_START_HEIGHT,
Expand Down Expand Up @@ -330,16 +329,32 @@ pub fn deliver_tx(
resp.log = e.to_string();
}
} else if is_convert_account(&tx) {
let hash = sha256::hash(req.get_tx());
if let Err(err) =
s.account_base_app.write().deliver_findora_tx(&tx, &hash.0)
{
info!(target: "abciapp", "deliver convert account tx failed: {err:?}");
match s.account_base_app.write().deliver_findora_tx(&tx) {
Ok(v) => {
if let Some(hash) = v {
let mut event = Event::new();
event.field_type = String::from("evm_hash");
let mut pair = Pair::new();
pair.set_key("hash".to_string().as_bytes().into());
pair.set_value(
format!("{:?}", hash).as_bytes().into(),
);
let attributes = vec![pair];
event.set_attributes(RepeatedField::from_vec(
attributes,
));
resp.events.push(event);
}
}
Err(err) => {
info!(target: "abciapp", "deliver convert account tx failed: {err:?}");

resp.code = 1;
resp.log =
format!("deliver convert account tx failed: {err:?}");
return resp;
resp.code = 1;
resp.log = format!(
"deliver convert account tx failed: {err:?}"
);
return resp;
}
}

if s.la.write().cache_transaction(tx).is_ok() {
Expand Down
6 changes: 2 additions & 4 deletions src/components/contracts/baseapp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,8 @@ impl BaseApp {
pub fn deliver_findora_tx(
&mut self,
tx: &FindoraTransaction,
hash: &[u8],
) -> Result<()> {
self.modules
.process_findora_tx(&self.deliver_state, tx, H256::from_slice(hash))
) -> Result<Option<H256>> {
self.modules.process_findora_tx(&self.deliver_state, tx)
}

pub fn consume_mint(&mut self) -> Option<Vec<NonConfidentialOutput>> {
Expand Down
10 changes: 4 additions & 6 deletions src/components/contracts/baseapp/src/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ impl ModuleManager {
&mut self,
ctx: &Context,
tx: &FindoraTransaction,
hash: H256,
) -> Result<()> {
) -> Result<Option<H256>> {
let (from, owner, amount, asset, lowlevel) =
check_convert_account(tx, ctx.header.height)?;

Expand All @@ -148,7 +147,6 @@ impl ModuleManager {
balance,
lowlevel,
transaction_index,
hash,
) {
Ok(r) => r,
Err(e) => {
Expand All @@ -166,10 +164,9 @@ impl ModuleManager {
U256::from(amount),
lowlevel,
transaction_index,
hash,
)?
};

let tx_hash = tx_status.transaction_hash;
TransactionIndex::insert(
&mut *ctx.db.write(),
&HA256::new(tx_status.transaction_hash),
Expand All @@ -178,11 +175,12 @@ impl ModuleManager {

pending_txs.push((tx, tx_status, receipt));

Ok(())
Ok(Some(tx_hash))
} else {
let balance = EthereumDecimalsMapping::from_native_token(U256::from(amount))
.ok_or_else(|| eg!("The transfer to account amount is too large"))?;
module_account::App::<BaseApp>::mint(ctx, &Address::from(owner), balance)
.map(|_| None)
}
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/components/contracts/modules/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ impl<C: Config> App<C> {
_value: U256,
_lowlevel: Vec<u8>,
transaction_index: u32,
transaction_hash: H256,
) -> Result<(TransactionV0, TransactionStatus, Receipt)> {
let function = self.contracts.bridge.function("withdrawAsset").c(d!())?;

Expand Down Expand Up @@ -176,7 +175,6 @@ impl<C: Config> App<C> {
let gas_price = U256::one();

Ok(Self::system_transaction(
transaction_hash,
input,
value,
action,
Expand All @@ -198,7 +196,6 @@ impl<C: Config> App<C> {
_value: U256,
_lowlevel: Vec<u8>,
transaction_index: u32,
transaction_hash: H256,
) -> Result<(TransactionV0, TransactionStatus, Receipt)> {
let function = self.contracts.bridge.function("withdrawFRA").c(d!())?;

Expand All @@ -225,7 +222,6 @@ impl<C: Config> App<C> {
let action = TransactionAction::Call(self.contracts.bridge_address);

Ok(Self::system_transaction(
transaction_hash,
input,
value,
action,
Expand All @@ -249,7 +245,6 @@ impl<C: Config> App<C> {
}
#[allow(clippy::too_many_arguments)]
fn system_transaction(
transaction_hash: H256,
input: Vec<u8>,
value: U256,
action: TransactionAction,
Expand Down Expand Up @@ -281,7 +276,7 @@ impl<C: Config> App<C> {
Self::logs_bloom(&logs, &mut logs_bloom);

let tx_status = TransactionStatus {
transaction_hash,
transaction_hash: tx.hash(),
transaction_index,
from,
to: Some(to),
Expand Down
2 changes: 1 addition & 1 deletion src/ledger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ abci_mock = []
lazy_static = "1.4.0"

[dependencies.fixed]
version = "1.19.0"
version = "=1.19.0"
features = ["f16", "serde"]

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
Expand Down

0 comments on commit 300d1cc

Please sign in to comment.