Skip to content

Commit

Permalink
Merge branch 'develop' into rc/v0.113.x
Browse files Browse the repository at this point in the history
  • Loading branch information
doitian committed Dec 19, 2023
2 parents 3985919 + 3e17637 commit 5150b88
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 17 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

15 changes: 14 additions & 1 deletion script/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,13 @@ impl<DL: CellDataProvider + HeaderProvider + ExtensionProvider + Send + Sync + C
Ok(machine)
}

fn run(&self, script_group: &ScriptGroup, max_cycles: Cycle) -> Result<Cycle, ScriptError> {
/// Runs a single program, then returns the exit code together with the entire
/// machine to the caller for more inspections.
pub fn detailed_run(
&self,
script_group: &ScriptGroup,
max_cycles: Cycle,
) -> Result<(i8, Machine), ScriptError> {
let program = self.extract_script(&script_group.script)?;
let context = Default::default();
let mut machine = self.build_machine(script_group, max_cycles, context)?;
Expand All @@ -1037,6 +1043,13 @@ impl<DL: CellDataProvider + HeaderProvider + ExtensionProvider + Send + Sync + C
.add_cycles_no_checking(transferred_byte_cycles(bytes))
.map_err(map_vm_internal_error)?;
let code = machine.run().map_err(map_vm_internal_error)?;

Ok((code, machine))
}

fn run(&self, script_group: &ScriptGroup, max_cycles: Cycle) -> Result<Cycle, ScriptError> {
let (code, machine) = self.detailed_run(script_group, max_cycles)?;

if code == 0 {
Ok(machine.machine.cycles())
} else {
Expand Down
10 changes: 5 additions & 5 deletions sync/src/filter/get_block_filter_check_points_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ impl<'a> GetBlockFilterCheckPointsProcess<'a> {
pub fn execute(self) -> Status {
let active_chain = self.filter.shared.active_chain();
let start_number: BlockNumber = self.message.to_entity().start_number().unpack();
let tip_number: BlockNumber = active_chain.tip_number();
let latest: BlockNumber = active_chain.get_latest_built_filter_block_number();

let mut block_filter_hashes = Vec::new();

if tip_number >= start_number {
if latest >= start_number {
for block_number in (start_number..start_number + BATCH_SIZE * CHECK_POINT_INTERVAL)
.step_by(CHECK_POINT_INTERVAL as usize)
{
Expand All @@ -59,9 +59,9 @@ impl<'a> GetBlockFilterCheckPointsProcess<'a> {
let message = packed::BlockFilterMessage::new_builder()
.set(content)
.build();
attempt!(send_message_to(self.nc.as_ref(), self.peer, &message));
attempt!(send_message_to(self.nc.as_ref(), self.peer, &message))
} else {
Status::ignored()
}

Status::ok()
}
}
4 changes: 2 additions & 2 deletions sync/src/filter/get_block_filter_hashes_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ impl<'a> GetBlockFilterHashesProcess<'a> {
pub fn execute(self) -> Status {
let active_chain = self.filter.shared.active_chain();
let start_number: BlockNumber = self.message.to_entity().start_number().unpack();
let tip_number: BlockNumber = active_chain.tip_number();
let latest: BlockNumber = active_chain.get_latest_built_filter_block_number();

let mut block_filter_hashes = Vec::new();

if tip_number >= start_number {
if latest >= start_number {
let parent_block_filter_hash = if start_number > 0 {
match active_chain
.get_block_hash(start_number - 1)
Expand Down
11 changes: 6 additions & 5 deletions sync/src/filter/get_block_filters_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ impl<'a> GetBlockFiltersProcess<'a> {
pub fn execute(self) -> Status {
let active_chain = self.filter.shared.active_chain();
let start_number: BlockNumber = self.message.to_entity().start_number().unpack();
let tip_number: BlockNumber = active_chain.tip_number();
if tip_number >= start_number {
let latest: BlockNumber = active_chain.get_latest_built_filter_block_number();

if latest >= start_number {
let mut block_hashes = Vec::new();
let mut filters = Vec::new();
for block_number in start_number..start_number + BATCH_SIZE {
Expand All @@ -58,9 +59,9 @@ impl<'a> GetBlockFiltersProcess<'a> {
let message = packed::BlockFilterMessage::new_builder()
.set(content)
.build();
attempt!(send_message_to(self.nc.as_ref(), self.peer, &message));
attempt!(send_message_to(self.nc.as_ref(), self.peer, &message))
} else {
Status::ignored()
}

Status::ok()
}
}
7 changes: 7 additions & 0 deletions sync/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2085,6 +2085,13 @@ impl ActiveChain {
self.store().get_block_filter_hash(hash)
}

pub fn get_latest_built_filter_block_number(&self) -> BlockNumber {
self.snapshot
.get_latest_built_filter_data_block_hash()
.and_then(|hash| self.snapshot.get_block_number(&hash))
.unwrap_or_default()
}

pub fn shared(&self) -> &SyncShared {
&self.shared
}
Expand Down

0 comments on commit 5150b88

Please sign in to comment.