Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat package failed transactions #684

Merged
merged 9 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com).

## [Unreleased]

- Support packaging failed transactions into layer2 block [#684](https://github.com/nervosnetwork/godwoken/pull/684)

## [v1.1.0-beta](https://github.com/nervosnetwork/godwoken-docker-prebuilds/pkgs/container/godwoken-prebuilds/21567994?tag=v1.1.0-beta) - 2022-05-08

> Note that Godwoken v1 is not an upgrade on the existing chain! Instead, v1 will be deployed as a new chain with tools to help users and developers migrate to the new chain.
Expand Down
16 changes: 9 additions & 7 deletions Cargo.lock

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

11 changes: 2 additions & 9 deletions crates/benches/benches/benchmarks/smt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,17 +244,10 @@ impl BenchExecutionEnvironment {

let run_result = self
.generator
.execute_transaction(
&self.chain,
&state,
&block_info,
&raw_tx,
L2TX_MAX_CYCLES,
None,
)
.execute_transaction(&self.chain, &state, &block_info, &raw_tx, L2TX_MAX_CYCLES)
.unwrap();

state.apply_run_result(&run_result).unwrap();
state.apply_run_result(&run_result.write).unwrap();

from_id += 1;
if from_id > end_account_id {
Expand Down
15 changes: 5 additions & 10 deletions crates/benches/benches/benchmarks/sudt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,10 @@ fn run_contract_get_result<S: State + CodeStore>(
};
let generator = Generator::new(backend_manage, account_lock_manage, rollup_ctx);
let chain_view = DummyChainStore;
let run_result = generator.execute_transaction(
&chain_view,
tree,
block_info,
&raw_tx,
L2TX_MAX_CYCLES,
None,
)?;
tree.apply_run_result(&run_result).expect("update state");
let run_result =
generator.execute_transaction(&chain_view, tree, block_info, &raw_tx, L2TX_MAX_CYCLES)?;
tree.apply_run_result(&run_result.write)
.expect("update state");
Ok(run_result)
}

Expand All @@ -109,7 +104,7 @@ fn run_contract<S: State + CodeStore>(
) -> Result<Vec<u8>, TransactionError> {
let run_result =
run_contract_get_result(rollup_config, tree, from_id, to_id, args, block_info)?;
Ok(run_result.return_data)
Ok(run_result.return_data.to_vec())
}

pub fn bench(c: &mut Criterion) {
Expand Down
2 changes: 1 addition & 1 deletion crates/block-producer/src/challenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use gw_challenge::revert::Revert;
use gw_challenge::types::{RevertContext, VerifyContext};
use gw_common::H256;
use gw_config::{BlockProducerConfig, DebugConfig};
use gw_generator::ChallengeContext;
use gw_generator::types::vm::ChallengeContext;
use gw_jsonrpc_types::test_mode::TestModePayload;
use gw_rpc_client::contract::ContractsCellDepManager;
use gw_rpc_client::rpc_client::RPCClient;
Expand Down
3 changes: 1 addition & 2 deletions crates/block-producer/src/replay_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,9 @@ impl ReplayBlock {
&block_info,
&raw_tx,
L2TX_MAX_CYCLES,
None,
)?;

state.apply_run_result(&run_result)?;
state.apply_run_result(&run_result.write)?;
let expected_checkpoint = state.calculate_state_checkpoint()?;
let checkpoint_index = withdrawals.len() + tx_index;
let block_checkpoint: H256 = match state_checkpoint_list.get(checkpoint_index) {
Expand Down
9 changes: 1 addition & 8 deletions crates/block-producer/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use gw_mem_pool::{
pool::{MemPool, MemPoolCreateArgs},
spawn_sub_mem_pool_task,
sync::p2p,
traits::MemPoolErrorTxHandler,
};
use gw_p2p_network::P2PNetwork;
use gw_rpc_client::{
Expand All @@ -51,7 +50,7 @@ use gw_types::{
prelude::*,
};
use gw_utils::{genesis_info::CKBGenesisInfo, since::EpochNumberWithFraction, wallet::Wallet};
use gw_web3_indexer::{ErrorReceiptIndexer, Web3Indexer};
use gw_web3_indexer::Web3Indexer;
use semver::Version;
use sqlx::{
postgres::{PgConnectOptions, PgPoolOptions},
Expand Down Expand Up @@ -593,10 +592,6 @@ pub async fn run(config: Config, skip_config_check: bool) -> Result<()> {
}
None => None,
};
let error_tx_handler = pg_pool.clone().map(|pool| {
Box::new(ErrorReceiptIndexer::new(pool))
as Box<dyn MemPoolErrorTxHandler + Send + Sync>
});
let notify_controller = {
let opt_ws_listen = config.rpc_server.err_receipt_ws_listen.as_ref();
opt_ws_listen.map(|_| NotifyService::new().start())
Expand All @@ -615,8 +610,6 @@ pub async fn run(config: Config, skip_config_check: bool) -> Result<()> {
store: base.store.clone(),
generator: base.generator.clone(),
provider: Box::new(mem_pool_provider),
error_tx_handler,
error_tx_receipt_notifier: notify_controller.clone(),
config: config.mem_pool.clone(),
node_mode: config.node_mode,
dynamic_config_manager: base.dynamic_config_manager.clone(),
Expand Down
2 changes: 1 addition & 1 deletion crates/block-producer/src/test_mode_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use gw_common::h256_ext::H256Ext;
use gw_common::merkle_utils::{calculate_ckb_merkle_root, ckb_merkle_leaf_hash};
use gw_common::smt::Blake2bHasher;
use gw_common::H256;
use gw_generator::ChallengeContext;
use gw_generator::types::vm::ChallengeContext;
use gw_jsonrpc_types::test_mode::ChallengeType;
use gw_jsonrpc_types::{godwoken::GlobalState as JsonGlobalState, test_mode::TestModePayload};
use gw_rpc_client::rpc_client::RPCClient;
Expand Down
3 changes: 2 additions & 1 deletion crates/chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use gw_config::ChainConfig;
use gw_generator::{
generator::{ApplyBlockArgs, ApplyBlockResult},
traits::StateExt,
ChallengeContext, Generator,
types::vm::ChallengeContext,
Generator,
};
use gw_jsonrpc_types::debugger::ReprMockTransaction;
use gw_mem_pool::pool::MemPool;
Expand Down
2 changes: 1 addition & 1 deletion crates/challenge/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use gw_common::state::State;
use gw_common::{blake2b::new_blake2b, H256};
use gw_generator::constants::L2TX_MAX_CYCLES;
use gw_generator::traits::StateExt;
use gw_generator::{ChallengeContext, Generator};
use gw_generator::{types::vm::ChallengeContext, Generator};
use gw_store::chain_view::ChainView;
use gw_store::state::mem_state_db::MemStateTree;
use gw_store::state::state_db::StateContext;
Expand Down
2 changes: 1 addition & 1 deletion crates/challenge/src/enter_challenge.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ckb_types::prelude::{Builder, Entity};
use gw_common::H256;
use gw_generator::ChallengeContext;
use gw_generator::types::vm::ChallengeContext;
use gw_types::core::{ScriptHashType, Status};
use gw_types::offchain::RollupContext;
use gw_types::packed::{
Expand Down
21 changes: 10 additions & 11 deletions crates/challenge/src/offchain/mock_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use gw_types::offchain::{RollupContext, RunResult};
use gw_types::packed::{
AccountMerkleState, BlockMerkleState, Byte32, Bytes, CCTransactionSignatureWitness,
CCTransactionWitness, CCWithdrawalWitness, CKBMerkleProof, ChallengeTarget, GlobalState,
L2Block, L2Transaction, RawL2Block, Script, ScriptReader, ScriptVec, SubmitTransactions,
SubmitWithdrawals, Uint64, WithdrawalRequestExtra,
L2Block, L2Transaction, RawL2Block, Script, ScriptVec, SubmitTransactions, SubmitWithdrawals,
Uint64, WithdrawalRequestExtra,
};
use gw_types::prelude::*;

Expand Down Expand Up @@ -149,7 +149,7 @@ impl MockBlockParam {
self.transactions.set_prev_txs_checkpoint(checkpoint);
}

mem_tree.apply_run_result(run_result)?;
mem_tree.apply_run_result(&run_result.write)?;
let post_account = mem_tree.merkle_state()?;
let checkpoint = calculate_state_checkpoint(
&post_account.merkle_root().unpack(),
Expand Down Expand Up @@ -476,7 +476,7 @@ impl MockBlockParam {
kv_state.insert(key.to_owned(), value);
}

for key in run_result.write_values.keys() {
for key in run_result.write.write_values.keys() {
if kv_state.contains_key(key) {
continue;
}
Expand All @@ -500,15 +500,14 @@ impl MockBlockParam {
let sender_script_hash = sender_script.hash();
let receiver_script_hash = receiver_script.hash();

for slice in run_result.get_scripts.iter() {
let script = ScriptReader::from_slice_should_be_ok(slice);

let script_hash = script.hash();
if script_hash == sender_script_hash || script_hash == receiver_script_hash {
for (script_hash, script) in run_result.get_scripts.iter() {
if script_hash.as_slice() == sender_script_hash
|| script_hash.as_slice() == receiver_script_hash
{
continue;
}

builder = builder.push(script.to_entity());
builder = builder.push(script.to_owned());
}

builder.build()
Expand All @@ -524,7 +523,7 @@ impl MockBlockParam {
let return_data_hash = {
let return_data_hash: [u8; 32] = {
let mut hasher = new_blake2b();
hasher.update(run_result.return_data.as_slice());
hasher.update(&run_result.return_data);
let mut hash = [0u8; 32];
hasher.finalize(&mut hash);
hash
Expand Down
2 changes: 1 addition & 1 deletion crates/challenge/src/offchain/mock_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use arc_swap::Guard;
use gw_common::blake2b::new_blake2b;
use gw_common::H256;
use gw_config::{BlockProducerConfig, ContractsCellDep};
use gw_generator::ChallengeContext;
use gw_generator::types::vm::ChallengeContext;
use gw_types::bytes::Bytes;
use gw_types::offchain::{CellInfo, InputCellInfo, RollupContext};
use gw_types::packed::{
Expand Down
3 changes: 1 addition & 2 deletions crates/generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ gw-config = { path = "../config" }
gw-store = { path = "../store" }
gw-traits = { path = "../traits" }
gw-ckb-hardfork = { path = "../ckb-hardfork" }
gw-tx-filter = { path = "../tx-filter" }
gw-dynamic-config = { path = "../dynamic-config"}
gw-utils = { path = "../utils"}
anyhow = "1.0"
blake2b-rs = "0.2"
ckb-vm = { version = "=0.20.0-rc5", features = ["detect-asm"] }
Expand Down
6 changes: 3 additions & 3 deletions crates/generator/src/backend_manage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use gw_types::bytes::Bytes;
use std::{collections::HashMap, fs};

#[cfg(has_asm)]
use crate::AotCode;
use crate::types::vm::AotCode;

#[derive(Clone)]
pub struct Backend {
Expand Down Expand Up @@ -89,8 +89,8 @@ impl BackendManage {
fn aot_compile(&self, code_bytes: &Bytes, vm_version: u32) -> Result<AotCode, ckb_vm::Error> {
log::info!("Compile AotCode with VMVersion::V{}", vm_version);
let vm_version = match vm_version {
0 => crate::VMVersion::V0,
1 => crate::VMVersion::V1,
0 => crate::types::vm::VMVersion::V0,
1 => crate::types::vm::VMVersion::V1,
ver => panic!("Unsupport VMVersion: {}", ver),
};
let mut aot_machine = ckb_vm::machine::aot::AotCompilingMachine::load(
Expand Down
6 changes: 4 additions & 2 deletions crates/generator/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ pub enum WithdrawalError {
max_size: usize,
withdrawal_size: usize,
},
#[error("Nonce Overflow")]
NonceOverflow,
}

impl From<WithdrawalError> for Error {
Expand All @@ -99,8 +101,6 @@ pub enum AccountError {
UnknownAccount,
#[error("Unknown script")]
UnknownScript,
#[error("Nonce Overflow")]
NonceOverflow,
#[error("can't find script for account {account_id}")]
ScriptNotFound { account_id: u32 },
#[error("can't find registry address")]
Expand Down Expand Up @@ -153,6 +153,8 @@ pub enum TransactionError {
InsufficientBalance,
#[error("Tx has no cost")]
NoCost,
#[error("Nonce Overflow")]
NonceOverflow,
}

impl From<VMError> for TransactionError {
Expand Down
Loading