mirror of
https://github.com/0glabs/0g-storage-node.git
synced 2024-12-26 00:05:17 +00:00
Fix an overflow bug in chunk sealing (#47)
This commit is contained in:
parent
6c1b0b35ec
commit
8c955ed5aa
@ -1,13 +1,14 @@
|
|||||||
use ethereum_types::H256;
|
use ethereum_types::H256;
|
||||||
use ssz_derive::{Decode as DeriveDecode, Encode as DeriveEncode};
|
use ssz_derive::{Decode as DeriveDecode, Encode as DeriveEncode};
|
||||||
use static_assertions::const_assert;
|
use static_assertions::const_assert;
|
||||||
|
use tracing::info;
|
||||||
|
|
||||||
use zgs_seal;
|
use zgs_seal;
|
||||||
use zgs_spec::{SEALS_PER_LOAD, SECTORS_PER_LOAD, SECTORS_PER_SEAL};
|
use zgs_spec::{SEALS_PER_LOAD, SECTORS_PER_LOAD, SECTORS_PER_SEAL};
|
||||||
|
|
||||||
use super::bitmap::WrappedBitmap;
|
use super::bitmap::WrappedBitmap;
|
||||||
|
|
||||||
#[derive(DeriveEncode, DeriveDecode)]
|
#[derive(Debug, DeriveEncode, DeriveDecode)]
|
||||||
pub struct SealContextInfo {
|
pub struct SealContextInfo {
|
||||||
/// The context digest for this seal group
|
/// The context digest for this seal group
|
||||||
context_digest: H256,
|
context_digest: H256,
|
||||||
@ -91,7 +92,7 @@ impl SealInfo {
|
|||||||
|
|
||||||
// 2. Compute the local end_seal_index
|
// 2. Compute the local end_seal_index
|
||||||
let end_seal_index = global_end_seal_index - self.load_index * SEALS_PER_LOAD as u64;
|
let end_seal_index = global_end_seal_index - self.load_index * SEALS_PER_LOAD as u64;
|
||||||
let end_seal_index = std::cmp::min(end_seal_index as u16, SEALS_PER_LOAD as u16);
|
let end_seal_index = std::cmp::min(end_seal_index, SEALS_PER_LOAD as u64) as u16;
|
||||||
let new_context = SealContextInfo {
|
let new_context = SealContextInfo {
|
||||||
context_digest,
|
context_digest,
|
||||||
end_seal_index,
|
end_seal_index,
|
||||||
@ -105,6 +106,7 @@ impl SealInfo {
|
|||||||
// Case 1: the new context is consistent with existing contexts (nothing to do)
|
// Case 1: the new context is consistent with existing contexts (nothing to do)
|
||||||
} else {
|
} else {
|
||||||
// Case 2: the new context should be inserted in the middle (may not happen)
|
// Case 2: the new context should be inserted in the middle (may not happen)
|
||||||
|
info!(target: "seal", "Unusual case of updating: load_index {}, new_context {:?}, existing_context {:?}", self.load_index, new_context, existing_context);
|
||||||
self.seal_contexts.insert(insert_position, new_context);
|
self.seal_contexts.insert(insert_position, new_context);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user