Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions 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 light-client-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ckb-jsonrpc-types = "1"
ckb-types = "1"
ckb-traits = "1"
ckb-systemtime = "1"
ckb-constant = "1"

ckb-light-client-lib = { path = "../light-client-lib" }
clap = { version = "4", features = ["cargo"] }
Expand Down
22 changes: 21 additions & 1 deletion light-client-bin/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use ckb_light_client_lib::{
};

use ckb_chain_spec::consensus::Consensus;
use ckb_constant::hardfork::{mainnet, testnet};
use ckb_jsonrpc_types::{
BlockView, EstimateCycles, HeaderView, JsonBytes, NodeAddress, RemoteNodeProtocol, Transaction,
Uint32,
Expand Down Expand Up @@ -804,13 +805,32 @@ impl NetRpc for NetRpcImpl {

impl TransactionRpc for TransactionRpcImpl {
fn send_transaction(&self, tx: Transaction) -> Result<H256> {
// Check sync status: reject if local tip hasn't passed the latest hardfork activation epoch
let local_tip_header = self.swc.storage().get_last_state().1.into_view();
let local_tip_epoch = local_tip_header.epoch().number();

// Determine the required hardfork epoch based on network
let required_hardfork_epoch = match self.consensus.id.as_str() {
mainnet::CHAIN_SPEC_NAME => mainnet::CKB2023_START_EPOCH,
testnet::CHAIN_SPEC_NAME => testnet::CKB2023_START_EPOCH,
_ => 0, // For other networks (dev/integration tests), no hardfork check
};

if local_tip_epoch < required_hardfork_epoch {
return Err(Error::invalid_params(format!(
"light client is not synced past hardfork: local tip epoch {} < required hardfork epoch {}",
local_tip_epoch,
required_hardfork_epoch
)));
}

let tx: packed::Transaction = tx.into();
let tx = tx.into_view();
let cycles = verify_tx(
tx.clone(),
&self.swc,
Arc::clone(&self.consensus),
&self.swc.storage().get_last_state().1.into_view(),
&local_tip_header,
)
.map_err(|e| Error::invalid_params(format!("invalid transaction: {:?}", e)))?;
self.swc
Expand Down
Loading