mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
Discussion draft: change DB Writer to take value references (#13672)
This commit is contained in:
@ -104,17 +104,17 @@ pub trait DbDupCursorRO<T: DupSort> {
|
||||
pub trait DbCursorRW<T: Table> {
|
||||
/// Database operation that will update an existing row if a specified value already
|
||||
/// exists in a table, and insert a new row if the specified value doesn't already exist
|
||||
fn upsert(&mut self, key: T::Key, value: T::Value) -> Result<(), DatabaseError>;
|
||||
fn upsert(&mut self, key: T::Key, value: &T::Value) -> Result<(), DatabaseError>;
|
||||
|
||||
/// Database operation that will insert a row at a given key. If the key is already
|
||||
/// present, the operation will result in an error.
|
||||
fn insert(&mut self, key: T::Key, value: T::Value) -> Result<(), DatabaseError>;
|
||||
fn insert(&mut self, key: T::Key, value: &T::Value) -> Result<(), DatabaseError>;
|
||||
|
||||
/// Append value to next cursor item.
|
||||
///
|
||||
/// This is efficient for pre-sorted data. If the data is not pre-sorted, use
|
||||
/// [`DbCursorRW::insert`].
|
||||
fn append(&mut self, key: T::Key, value: T::Value) -> Result<(), DatabaseError>;
|
||||
fn append(&mut self, key: T::Key, value: &T::Value) -> Result<(), DatabaseError>;
|
||||
|
||||
/// Delete current value that cursor points to
|
||||
fn delete_current(&mut self) -> Result<(), DatabaseError>;
|
||||
|
||||
@ -220,7 +220,7 @@ impl<T: Table> DbCursorRW<T> for CursorMock {
|
||||
fn upsert(
|
||||
&mut self,
|
||||
_key: <T as Table>::Key,
|
||||
_value: <T as Table>::Value,
|
||||
_value: &<T as Table>::Value,
|
||||
) -> Result<(), DatabaseError> {
|
||||
Ok(())
|
||||
}
|
||||
@ -228,7 +228,7 @@ impl<T: Table> DbCursorRW<T> for CursorMock {
|
||||
fn insert(
|
||||
&mut self,
|
||||
_key: <T as Table>::Key,
|
||||
_value: <T as Table>::Value,
|
||||
_value: &<T as Table>::Value,
|
||||
) -> Result<(), DatabaseError> {
|
||||
Ok(())
|
||||
}
|
||||
@ -236,7 +236,7 @@ impl<T: Table> DbCursorRW<T> for CursorMock {
|
||||
fn append(
|
||||
&mut self,
|
||||
_key: <T as Table>::Key,
|
||||
_value: <T as Table>::Value,
|
||||
_value: &<T as Table>::Value,
|
||||
) -> Result<(), DatabaseError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -165,7 +165,7 @@ impl Compress for IntegerList {
|
||||
self.to_bytes()
|
||||
}
|
||||
|
||||
fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(self, buf: &mut B) {
|
||||
fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(&self, buf: &mut B) {
|
||||
self.to_mut_bytes(buf)
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,8 +194,8 @@ macro_rules! impl_compression_for_compact {
|
||||
impl$(<$($generic: core::fmt::Debug + Send + Sync + Compact),*>)? Compress for $name$(<$($generic),*>)? {
|
||||
type Compressed = Vec<u8>;
|
||||
|
||||
fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(self, buf: &mut B) {
|
||||
let _ = Compact::to_compact(&self, buf);
|
||||
fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(&self, buf: &mut B) {
|
||||
let _ = Compact::to_compact(self, buf);
|
||||
}
|
||||
}
|
||||
|
||||
@ -253,8 +253,8 @@ macro_rules! impl_compression_fixed_compact {
|
||||
Some(self.as_ref())
|
||||
}
|
||||
|
||||
fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(self, buf: &mut B) {
|
||||
let _ = Compact::to_compact(&self, buf);
|
||||
fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(&self, buf: &mut B) {
|
||||
let _ = Compact::to_compact(self, buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ where
|
||||
parity_scale_codec::Encode::encode(&self)
|
||||
}
|
||||
|
||||
fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(self, buf: &mut B) {
|
||||
fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(&self, buf: &mut B) {
|
||||
parity_scale_codec::Encode::encode_to(&self, OutputCompat::wrap_mut(buf));
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ pub trait Compress: Send + Sync + Sized + Debug {
|
||||
}
|
||||
|
||||
/// Compresses data to a given buffer.
|
||||
fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(self, buf: &mut B);
|
||||
fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(&self, buf: &mut B);
|
||||
}
|
||||
|
||||
/// Trait that will transform the data to be read from the DB.
|
||||
@ -132,7 +132,7 @@ pub trait TableImporter: DbTxMut {
|
||||
|
||||
for kv in source_tx.cursor_read::<T>()?.walk(None)? {
|
||||
let (k, v) = kv?;
|
||||
destination_cursor.append(k, v)?;
|
||||
destination_cursor.append(k, &v)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@ -157,7 +157,7 @@ pub trait TableImporter: DbTxMut {
|
||||
};
|
||||
for row in source_range? {
|
||||
let (key, value) = row?;
|
||||
destination_cursor.append(key, value)?;
|
||||
destination_cursor.append(key, &value)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@ -252,7 +252,11 @@ where
|
||||
Vec::new(),
|
||||
);
|
||||
|
||||
provider.write_state(execution_outcome, OriginalValuesKnown::Yes, StorageLocation::Database)?;
|
||||
provider.write_state(
|
||||
&execution_outcome,
|
||||
OriginalValuesKnown::Yes,
|
||||
StorageLocation::Database,
|
||||
)?;
|
||||
|
||||
trace!(target: "reth::cli", "Inserted state");
|
||||
|
||||
|
||||
@ -137,7 +137,7 @@ where
|
||||
let tx = db.tx_mut().expect("tx");
|
||||
let mut crsr = tx.cursor_write::<T>().expect("cursor");
|
||||
for (k, _, v, _) in input {
|
||||
crsr.append(k, v).expect("submit");
|
||||
crsr.append(k, &v).expect("submit");
|
||||
}
|
||||
tx.inner.commit().unwrap()
|
||||
},
|
||||
@ -157,7 +157,7 @@ where
|
||||
let mut crsr = tx.cursor_write::<T>().expect("cursor");
|
||||
for index in RANDOM_INDEXES {
|
||||
let (k, _, v, _) = input.get(index).unwrap().clone();
|
||||
crsr.insert(k, v).expect("submit");
|
||||
crsr.insert(k, &v).expect("submit");
|
||||
}
|
||||
|
||||
tx.inner.commit().unwrap()
|
||||
|
||||
@ -184,7 +184,7 @@ where
|
||||
let mut crsr = tx.cursor_write::<T>().expect("cursor");
|
||||
black_box({
|
||||
for (k, v) in input {
|
||||
crsr.append(k, v).expect("submit");
|
||||
crsr.append(k, &v).expect("submit");
|
||||
}
|
||||
|
||||
tx.inner.commit().unwrap()
|
||||
@ -202,7 +202,7 @@ where
|
||||
let mut crsr = tx.cursor_write::<T>().expect("cursor");
|
||||
black_box({
|
||||
for (k, v) in input {
|
||||
crsr.insert(k, v).expect("submit");
|
||||
crsr.insert(k, &v).expect("submit");
|
||||
}
|
||||
|
||||
tx.inner.commit().unwrap()
|
||||
|
||||
@ -241,7 +241,7 @@ impl<T: Table> DbCursorRW<T> for Cursor<RW, T> {
|
||||
/// it will append the value to the subkey, even if the subkeys are the same. So if you want
|
||||
/// to properly upsert, you'll need to `seek_exact` & `delete_current` if the key+subkey was
|
||||
/// found, before calling `upsert`.
|
||||
fn upsert(&mut self, key: T::Key, value: T::Value) -> Result<(), DatabaseError> {
|
||||
fn upsert(&mut self, key: T::Key, value: &T::Value) -> Result<(), DatabaseError> {
|
||||
let key = key.encode();
|
||||
let value = compress_to_buf_or_ref!(self, value);
|
||||
self.execute_with_operation_metric(
|
||||
@ -263,7 +263,7 @@ impl<T: Table> DbCursorRW<T> for Cursor<RW, T> {
|
||||
)
|
||||
}
|
||||
|
||||
fn insert(&mut self, key: T::Key, value: T::Value) -> Result<(), DatabaseError> {
|
||||
fn insert(&mut self, key: T::Key, value: &T::Value) -> Result<(), DatabaseError> {
|
||||
let key = key.encode();
|
||||
let value = compress_to_buf_or_ref!(self, value);
|
||||
self.execute_with_operation_metric(
|
||||
@ -287,7 +287,7 @@ impl<T: Table> DbCursorRW<T> for Cursor<RW, T> {
|
||||
|
||||
/// Appends the data to the end of the table. Consequently, the append operation
|
||||
/// will fail if the inserted key is less than the last table key
|
||||
fn append(&mut self, key: T::Key, value: T::Value) -> Result<(), DatabaseError> {
|
||||
fn append(&mut self, key: T::Key, value: &T::Value) -> Result<(), DatabaseError> {
|
||||
let key = key.encode();
|
||||
let value = compress_to_buf_or_ref!(self, value);
|
||||
self.execute_with_operation_metric(
|
||||
|
||||
@ -479,7 +479,7 @@ impl DatabaseEnv {
|
||||
if Some(&version) != last_version.as_ref() {
|
||||
version_cursor.upsert(
|
||||
SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default().as_secs(),
|
||||
version,
|
||||
&version,
|
||||
)?;
|
||||
tx.commit()?;
|
||||
}
|
||||
@ -580,8 +580,8 @@ mod tests {
|
||||
let entry_0 = StorageEntry { key: B256::with_last_byte(1), value: U256::from(0) };
|
||||
let entry_1 = StorageEntry { key: B256::with_last_byte(1), value: U256::from(1) };
|
||||
|
||||
dup_cursor.upsert(Address::with_last_byte(1), entry_0).expect(ERROR_UPSERT);
|
||||
dup_cursor.upsert(Address::with_last_byte(1), entry_1).expect(ERROR_UPSERT);
|
||||
dup_cursor.upsert(Address::with_last_byte(1), &entry_0).expect(ERROR_UPSERT);
|
||||
dup_cursor.upsert(Address::with_last_byte(1), &entry_1).expect(ERROR_UPSERT);
|
||||
|
||||
assert_eq!(
|
||||
dup_cursor.walk(None).unwrap().collect::<Result<Vec<_>, _>>(),
|
||||
@ -910,12 +910,12 @@ mod tests {
|
||||
let mut cursor = tx.cursor_write::<CanonicalHeaders>().unwrap();
|
||||
|
||||
// INSERT
|
||||
assert_eq!(cursor.insert(key_to_insert, B256::ZERO), Ok(()));
|
||||
assert_eq!(cursor.insert(key_to_insert, &B256::ZERO), Ok(()));
|
||||
assert_eq!(cursor.current(), Ok(Some((key_to_insert, B256::ZERO))));
|
||||
|
||||
// INSERT (failure)
|
||||
assert_eq!(
|
||||
cursor.insert(key_to_insert, B256::ZERO),
|
||||
cursor.insert(key_to_insert, &B256::ZERO),
|
||||
Err(DatabaseWriteError {
|
||||
info: Error::KeyExist.into(),
|
||||
operation: DatabaseWriteOperation::CursorInsert,
|
||||
@ -947,11 +947,11 @@ mod tests {
|
||||
let subkey2 = B256::random();
|
||||
|
||||
let entry1 = StorageEntry { key: subkey1, value: U256::ZERO };
|
||||
assert!(dup_cursor.insert(key, entry1).is_ok());
|
||||
assert!(dup_cursor.insert(key, &entry1).is_ok());
|
||||
|
||||
// Can't insert
|
||||
let entry2 = StorageEntry { key: subkey2, value: U256::ZERO };
|
||||
assert!(dup_cursor.insert(key, entry2).is_err());
|
||||
assert!(dup_cursor.insert(key, &entry2).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -964,9 +964,9 @@ mod tests {
|
||||
let key3 = Address::with_last_byte(3);
|
||||
let mut cursor = tx.cursor_write::<PlainAccountState>().unwrap();
|
||||
|
||||
assert!(cursor.insert(key1, Account::default()).is_ok());
|
||||
assert!(cursor.insert(key2, Account::default()).is_ok());
|
||||
assert!(cursor.insert(key3, Account::default()).is_ok());
|
||||
assert!(cursor.insert(key1, &Account::default()).is_ok());
|
||||
assert!(cursor.insert(key2, &Account::default()).is_ok());
|
||||
assert!(cursor.insert(key3, &Account::default()).is_ok());
|
||||
|
||||
// Seek & delete key2
|
||||
cursor.seek_exact(key2).unwrap();
|
||||
@ -1002,7 +1002,7 @@ mod tests {
|
||||
assert_eq!(cursor.current(), Ok(Some((9, B256::ZERO))));
|
||||
|
||||
for pos in (2..=8).step_by(2) {
|
||||
assert_eq!(cursor.insert(pos, B256::ZERO), Ok(()));
|
||||
assert_eq!(cursor.insert(pos, &B256::ZERO), Ok(()));
|
||||
assert_eq!(cursor.current(), Ok(Some((pos, B256::ZERO))));
|
||||
}
|
||||
tx.commit().expect(ERROR_COMMIT);
|
||||
@ -1031,7 +1031,7 @@ mod tests {
|
||||
let key_to_append = 5;
|
||||
let tx = db.tx_mut().expect(ERROR_INIT_TX);
|
||||
let mut cursor = tx.cursor_write::<CanonicalHeaders>().unwrap();
|
||||
assert_eq!(cursor.append(key_to_append, B256::ZERO), Ok(()));
|
||||
assert_eq!(cursor.append(key_to_append, &B256::ZERO), Ok(()));
|
||||
tx.commit().expect(ERROR_COMMIT);
|
||||
|
||||
// Confirm the result
|
||||
@ -1059,7 +1059,7 @@ mod tests {
|
||||
let tx = db.tx_mut().expect(ERROR_INIT_TX);
|
||||
let mut cursor = tx.cursor_write::<CanonicalHeaders>().unwrap();
|
||||
assert_eq!(
|
||||
cursor.append(key_to_append, B256::ZERO),
|
||||
cursor.append(key_to_append, &B256::ZERO),
|
||||
Err(DatabaseWriteError {
|
||||
info: Error::KeyMismatch.into(),
|
||||
operation: DatabaseWriteOperation::CursorAppend,
|
||||
@ -1088,15 +1088,15 @@ mod tests {
|
||||
let key = Address::random();
|
||||
|
||||
let account = Account::default();
|
||||
cursor.upsert(key, account).expect(ERROR_UPSERT);
|
||||
cursor.upsert(key, &account).expect(ERROR_UPSERT);
|
||||
assert_eq!(cursor.seek_exact(key), Ok(Some((key, account))));
|
||||
|
||||
let account = Account { nonce: 1, ..Default::default() };
|
||||
cursor.upsert(key, account).expect(ERROR_UPSERT);
|
||||
cursor.upsert(key, &account).expect(ERROR_UPSERT);
|
||||
assert_eq!(cursor.seek_exact(key), Ok(Some((key, account))));
|
||||
|
||||
let account = Account { nonce: 2, ..Default::default() };
|
||||
cursor.upsert(key, account).expect(ERROR_UPSERT);
|
||||
cursor.upsert(key, &account).expect(ERROR_UPSERT);
|
||||
assert_eq!(cursor.seek_exact(key), Ok(Some((key, account))));
|
||||
|
||||
let mut dup_cursor = tx.cursor_dup_write::<PlainStorageState>().unwrap();
|
||||
@ -1104,12 +1104,12 @@ mod tests {
|
||||
|
||||
let value = U256::from(1);
|
||||
let entry1 = StorageEntry { key: subkey, value };
|
||||
dup_cursor.upsert(key, entry1).expect(ERROR_UPSERT);
|
||||
dup_cursor.upsert(key, &entry1).expect(ERROR_UPSERT);
|
||||
assert_eq!(dup_cursor.seek_by_key_subkey(key, subkey), Ok(Some(entry1)));
|
||||
|
||||
let value = U256::from(2);
|
||||
let entry2 = StorageEntry { key: subkey, value };
|
||||
dup_cursor.upsert(key, entry2).expect(ERROR_UPSERT);
|
||||
dup_cursor.upsert(key, &entry2).expect(ERROR_UPSERT);
|
||||
assert_eq!(dup_cursor.seek_by_key_subkey(key, subkey), Ok(Some(entry1)));
|
||||
assert_eq!(dup_cursor.next_dup_val(), Ok(Some(entry2)));
|
||||
}
|
||||
@ -1127,7 +1127,7 @@ mod tests {
|
||||
.try_for_each(|val| {
|
||||
cursor.append(
|
||||
transition_id,
|
||||
AccountBeforeTx { address: Address::with_last_byte(val), info: None },
|
||||
&AccountBeforeTx { address: Address::with_last_byte(val), info: None },
|
||||
)
|
||||
})
|
||||
.expect(ERROR_APPEND);
|
||||
@ -1153,7 +1153,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
cursor.append(
|
||||
transition_id - 1,
|
||||
AccountBeforeTx { address: Address::with_last_byte(subkey_to_append), info: None }
|
||||
&AccountBeforeTx { address: Address::with_last_byte(subkey_to_append), info: None }
|
||||
),
|
||||
Err(DatabaseWriteError {
|
||||
info: Error::KeyMismatch.into(),
|
||||
@ -1166,7 +1166,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
cursor.append(
|
||||
transition_id,
|
||||
AccountBeforeTx { address: Address::with_last_byte(subkey_to_append), info: None }
|
||||
&AccountBeforeTx { address: Address::with_last_byte(subkey_to_append), info: None }
|
||||
),
|
||||
Ok(())
|
||||
);
|
||||
|
||||
@ -168,7 +168,7 @@ impl<V: Value> Compress for RawValue<V> {
|
||||
self.value
|
||||
}
|
||||
|
||||
fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(self, buf: &mut B) {
|
||||
fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(&self, buf: &mut B) {
|
||||
buf.put_slice(self.value.as_slice())
|
||||
}
|
||||
}
|
||||
|
||||
@ -1810,7 +1810,7 @@ mod tests {
|
||||
.into_iter()
|
||||
.map(|b| b.seal_with_senders().expect("failed to seal block with senders"))
|
||||
.collect(),
|
||||
ExecutionOutcome {
|
||||
&ExecutionOutcome {
|
||||
bundle: BundleState::new(
|
||||
database_state.into_iter().map(|(address, (account, _))| {
|
||||
(address, None, Some(account.into()), Default::default())
|
||||
|
||||
@ -1730,7 +1730,7 @@ mod tests {
|
||||
.into_iter()
|
||||
.map(|b| b.seal_with_senders().expect("failed to seal block with senders"))
|
||||
.collect(),
|
||||
ExecutionOutcome {
|
||||
&ExecutionOutcome {
|
||||
bundle: BundleState::new(
|
||||
database_state.into_iter().map(|(address, (account, _))| {
|
||||
(address, None, Some(account.into()), Default::default())
|
||||
|
||||
@ -1670,7 +1670,7 @@ impl<TX: DbTxMut, N: NodeTypes> StageCheckpointWriter for DatabaseProvider<TX, N
|
||||
let (_, checkpoint) = cursor.seek_exact(stage_id.to_string())?.unwrap_or_default();
|
||||
cursor.upsert(
|
||||
stage_id.to_string(),
|
||||
StageCheckpoint {
|
||||
&StageCheckpoint {
|
||||
block_number,
|
||||
..if drop_stage_checkpoint { Default::default() } else { checkpoint }
|
||||
},
|
||||
@ -1751,7 +1751,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypesForProvider> StateWriter
|
||||
|
||||
fn write_state(
|
||||
&self,
|
||||
execution_outcome: ExecutionOutcome<Self::Receipt>,
|
||||
execution_outcome: &ExecutionOutcome<Self::Receipt>,
|
||||
is_value_known: OriginalValuesKnown,
|
||||
write_receipts_to: StorageLocation,
|
||||
) -> ProviderResult<()> {
|
||||
@ -1785,7 +1785,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypesForProvider> StateWriter
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
for (idx, receipts) in execution_outcome.receipts.into_iter().enumerate() {
|
||||
for (idx, receipts) in execution_outcome.receipts.iter().enumerate() {
|
||||
let block_number = execution_outcome.first_block + idx as u64;
|
||||
|
||||
// Increment block number for receipts static file writer
|
||||
@ -1798,11 +1798,11 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypesForProvider> StateWriter
|
||||
.map(|(_, indices)| indices.first_tx_num())
|
||||
.ok_or(ProviderError::BlockBodyIndicesNotFound(block_number))?;
|
||||
|
||||
for (idx, receipt) in receipts.into_iter().enumerate() {
|
||||
for (idx, receipt) in receipts.iter().enumerate() {
|
||||
let receipt_idx = first_tx_index + idx as u64;
|
||||
if let Some(receipt) = receipt {
|
||||
if let Some(writer) = &mut receipts_static_writer {
|
||||
writer.append_receipt(receipt_idx, &receipt)?;
|
||||
writer.append_receipt(receipt_idx, receipt)?;
|
||||
}
|
||||
|
||||
if let Some(cursor) = &mut receipts_cursor {
|
||||
@ -1897,7 +1897,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypesForProvider> StateWriter
|
||||
for (address, account) in changes.accounts {
|
||||
if let Some(account) = account {
|
||||
tracing::trace!(?address, "Updating plain state account");
|
||||
accounts_cursor.upsert(address, account.into())?;
|
||||
accounts_cursor.upsert(address, &account.into())?;
|
||||
} else if accounts_cursor.seek_exact(address)?.is_some() {
|
||||
tracing::trace!(?address, "Deleting plain state account");
|
||||
accounts_cursor.delete_current()?;
|
||||
@ -1908,7 +1908,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypesForProvider> StateWriter
|
||||
tracing::trace!(len = changes.contracts.len(), "Writing bytecodes");
|
||||
let mut bytecodes_cursor = self.tx_ref().cursor_write::<tables::Bytecodes>()?;
|
||||
for (hash, bytecode) in changes.contracts {
|
||||
bytecodes_cursor.upsert(hash, Bytecode(bytecode))?;
|
||||
bytecodes_cursor.upsert(hash, &Bytecode(bytecode))?;
|
||||
}
|
||||
|
||||
// Write new storage state and wipe storage if needed.
|
||||
@ -1936,7 +1936,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypesForProvider> StateWriter
|
||||
}
|
||||
|
||||
if !entry.value.is_zero() {
|
||||
storages_cursor.upsert(address, entry)?;
|
||||
storages_cursor.upsert(address, &entry)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1949,7 +1949,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypesForProvider> StateWriter
|
||||
let mut hashed_accounts_cursor = self.tx_ref().cursor_write::<tables::HashedAccounts>()?;
|
||||
for (hashed_address, account) in hashed_state.accounts().accounts_sorted() {
|
||||
if let Some(account) = account {
|
||||
hashed_accounts_cursor.upsert(hashed_address, account)?;
|
||||
hashed_accounts_cursor.upsert(hashed_address, &account)?;
|
||||
} else if hashed_accounts_cursor.seek_exact(hashed_address)?.is_some() {
|
||||
hashed_accounts_cursor.delete_current()?;
|
||||
}
|
||||
@ -1975,7 +1975,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypesForProvider> StateWriter
|
||||
}
|
||||
|
||||
if !entry.value.is_zero() {
|
||||
hashed_storage_cursor.upsert(*hashed_address, entry)?;
|
||||
hashed_storage_cursor.upsert(*hashed_address, &entry)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2047,7 +2047,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypesForProvider> StateWriter
|
||||
if old_account != new_account {
|
||||
let existing_entry = plain_accounts_cursor.seek_exact(*address)?;
|
||||
if let Some(account) = old_account {
|
||||
plain_accounts_cursor.upsert(*address, *account)?;
|
||||
plain_accounts_cursor.upsert(*address, account)?;
|
||||
} else if existing_entry.is_some() {
|
||||
plain_accounts_cursor.delete_current()?;
|
||||
}
|
||||
@ -2068,7 +2068,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypesForProvider> StateWriter
|
||||
|
||||
// insert value if needed
|
||||
if !old_storage_value.is_zero() {
|
||||
plain_storage_cursor.upsert(*address, storage_entry)?;
|
||||
plain_storage_cursor.upsert(*address, &storage_entry)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2147,7 +2147,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypesForProvider> StateWriter
|
||||
if old_account != new_account {
|
||||
let existing_entry = plain_accounts_cursor.seek_exact(*address)?;
|
||||
if let Some(account) = old_account {
|
||||
plain_accounts_cursor.upsert(*address, *account)?;
|
||||
plain_accounts_cursor.upsert(*address, account)?;
|
||||
} else if existing_entry.is_some() {
|
||||
plain_accounts_cursor.delete_current()?;
|
||||
}
|
||||
@ -2168,7 +2168,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypesForProvider> StateWriter
|
||||
|
||||
// insert value if needed
|
||||
if !old_storage_value.is_zero() {
|
||||
plain_storage_cursor.upsert(*address, storage_entry)?;
|
||||
plain_storage_cursor.upsert(*address, &storage_entry)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2255,7 +2255,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypes> TrieWriter for DatabaseProvider
|
||||
Some(node) => {
|
||||
if !nibbles.0.is_empty() {
|
||||
num_entries += 1;
|
||||
account_trie_cursor.upsert(nibbles, node.clone())?;
|
||||
account_trie_cursor.upsert(nibbles, node)?;
|
||||
}
|
||||
}
|
||||
None => {
|
||||
@ -2330,7 +2330,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypes> HashingWriter for DatabaseProvi
|
||||
let mut hashed_accounts_cursor = self.tx.cursor_write::<tables::HashedAccounts>()?;
|
||||
for (hashed_address, account) in &hashed_accounts {
|
||||
if let Some(account) = account {
|
||||
hashed_accounts_cursor.upsert(*hashed_address, *account)?;
|
||||
hashed_accounts_cursor.upsert(*hashed_address, account)?;
|
||||
} else if hashed_accounts_cursor.seek_exact(*hashed_address)?.is_some() {
|
||||
hashed_accounts_cursor.delete_current()?;
|
||||
}
|
||||
@ -2360,7 +2360,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypes> HashingWriter for DatabaseProvi
|
||||
changesets.into_iter().map(|(ad, ac)| (keccak256(ad), ac)).collect::<BTreeMap<_, _>>();
|
||||
for (hashed_address, account) in &hashed_accounts {
|
||||
if let Some(account) = account {
|
||||
hashed_accounts_cursor.upsert(*hashed_address, *account)?;
|
||||
hashed_accounts_cursor.upsert(*hashed_address, account)?;
|
||||
} else if hashed_accounts_cursor.seek_exact(*hashed_address)?.is_some() {
|
||||
hashed_accounts_cursor.delete_current()?;
|
||||
}
|
||||
@ -2397,7 +2397,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypes> HashingWriter for DatabaseProvi
|
||||
}
|
||||
|
||||
if !value.is_zero() {
|
||||
hashed_storage.upsert(hashed_address, StorageEntry { key, value })?;
|
||||
hashed_storage.upsert(hashed_address, &StorageEntry { key, value })?;
|
||||
}
|
||||
}
|
||||
Ok(hashed_storage_keys)
|
||||
@ -2449,7 +2449,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypes> HashingWriter for DatabaseProvi
|
||||
}
|
||||
|
||||
if !value.is_zero() {
|
||||
hashed_storage_cursor.upsert(hashed_address, StorageEntry { key, value })?;
|
||||
hashed_storage_cursor.upsert(hashed_address, &StorageEntry { key, value })?;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
@ -2561,7 +2561,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypes> HistoryWriter for DatabaseProvi
|
||||
if !partial_shard.is_empty() {
|
||||
cursor.insert(
|
||||
ShardedKey::last(address),
|
||||
BlockNumberList::new_pre_sorted(partial_shard),
|
||||
&BlockNumberList::new_pre_sorted(partial_shard),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
@ -2619,7 +2619,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypes> HistoryWriter for DatabaseProvi
|
||||
if !partial_shard.is_empty() {
|
||||
cursor.insert(
|
||||
StorageShardedKey::last(address, storage_key),
|
||||
BlockNumberList::new_pre_sorted(partial_shard),
|
||||
&BlockNumberList::new_pre_sorted(partial_shard),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
@ -2864,7 +2864,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypesForProvider + 'static> BlockWrite
|
||||
let mut durations_recorder = metrics::DurationsRecorder::default();
|
||||
|
||||
// insert block meta
|
||||
block_indices_cursor.append(*block_number, block_indices)?;
|
||||
block_indices_cursor.append(*block_number, &block_indices)?;
|
||||
|
||||
durations_recorder.record_relative(metrics::Action::InsertBlockBodyIndices);
|
||||
|
||||
@ -2872,7 +2872,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypesForProvider + 'static> BlockWrite
|
||||
|
||||
// write transaction block index
|
||||
if !body.transactions().is_empty() {
|
||||
tx_block_cursor.append(block_indices.last_tx_num(), *block_number)?;
|
||||
tx_block_cursor.append(block_indices.last_tx_num(), block_number)?;
|
||||
durations_recorder.record_relative(metrics::Action::InsertTransactionBlocks);
|
||||
}
|
||||
|
||||
@ -2882,7 +2882,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypesForProvider + 'static> BlockWrite
|
||||
writer.append_transaction(next_tx_num, transaction)?;
|
||||
}
|
||||
if let Some(cursor) = tx_cursor.as_mut() {
|
||||
cursor.append(next_tx_num, transaction.clone())?;
|
||||
cursor.append(next_tx_num, transaction)?;
|
||||
}
|
||||
|
||||
// Increment transaction id for each transaction.
|
||||
@ -2992,7 +2992,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypesForProvider + 'static> BlockWrite
|
||||
fn append_blocks_with_state(
|
||||
&self,
|
||||
blocks: Vec<SealedBlockWithSenders<Self::Block>>,
|
||||
execution_outcome: ExecutionOutcome<Self::Receipt>,
|
||||
execution_outcome: &ExecutionOutcome<Self::Receipt>,
|
||||
hashed_state: HashedPostStateSorted,
|
||||
trie_updates: TrieUpdates,
|
||||
) -> ProviderResult<()> {
|
||||
|
||||
@ -133,7 +133,7 @@ pub trait BlockWriter: Send + Sync {
|
||||
fn append_blocks_with_state(
|
||||
&self,
|
||||
blocks: Vec<SealedBlockWithSenders<Self::Block>>,
|
||||
execution_outcome: ExecutionOutcome<Self::Receipt>,
|
||||
execution_outcome: &ExecutionOutcome<Self::Receipt>,
|
||||
hashed_state: HashedPostStateSorted,
|
||||
trie_updates: TrieUpdates,
|
||||
) -> ProviderResult<()>;
|
||||
|
||||
@ -18,7 +18,7 @@ pub trait StateWriter {
|
||||
/// `Some`. It should be `None` if there is any kind of pruning/filtering over the receipts.
|
||||
fn write_state(
|
||||
&self,
|
||||
execution_outcome: ExecutionOutcome<Self::Receipt>,
|
||||
execution_outcome: &ExecutionOutcome<Self::Receipt>,
|
||||
is_value_known: OriginalValuesKnown,
|
||||
write_receipts_to: StorageLocation,
|
||||
) -> ProviderResult<()>;
|
||||
|
||||
@ -169,7 +169,7 @@ where
|
||||
// Write state and changesets to the database.
|
||||
// Must be written after blocks because of the receipt lookup.
|
||||
self.database().write_state(
|
||||
Arc::unwrap_or_clone(execution_output),
|
||||
&execution_output,
|
||||
OriginalValuesKnown::No,
|
||||
StorageLocation::StaticFiles,
|
||||
)?;
|
||||
@ -273,10 +273,13 @@ mod tests {
|
||||
for address in addresses {
|
||||
let hashed_address = keccak256(address);
|
||||
accounts_cursor
|
||||
.insert(hashed_address, Account { nonce: 1, ..Default::default() })
|
||||
.insert(hashed_address, &Account { nonce: 1, ..Default::default() })
|
||||
.unwrap();
|
||||
storage_cursor
|
||||
.insert(hashed_address, StorageEntry { key: hashed_slot, value: U256::from(1) })
|
||||
.insert(
|
||||
hashed_address,
|
||||
&StorageEntry { key: hashed_slot, value: U256::from(1) },
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
provider_rw.commit().unwrap();
|
||||
@ -496,7 +499,7 @@ mod tests {
|
||||
let outcome =
|
||||
ExecutionOutcome::new(state.take_bundle(), Receipts::default(), 1, Vec::new());
|
||||
provider
|
||||
.write_state(outcome, OriginalValuesKnown::Yes, StorageLocation::Database)
|
||||
.write_state(&outcome, OriginalValuesKnown::Yes, StorageLocation::Database)
|
||||
.expect("Could not write bundle state to DB");
|
||||
|
||||
// Check plain storage state
|
||||
@ -596,7 +599,7 @@ mod tests {
|
||||
let outcome =
|
||||
ExecutionOutcome::new(state.take_bundle(), Receipts::default(), 2, Vec::new());
|
||||
provider
|
||||
.write_state(outcome, OriginalValuesKnown::Yes, StorageLocation::Database)
|
||||
.write_state(&outcome, OriginalValuesKnown::Yes, StorageLocation::Database)
|
||||
.expect("Could not write bundle state to DB");
|
||||
|
||||
assert_eq!(
|
||||
@ -663,7 +666,7 @@ mod tests {
|
||||
let outcome =
|
||||
ExecutionOutcome::new(init_state.take_bundle(), Receipts::default(), 0, Vec::new());
|
||||
provider
|
||||
.write_state(outcome, OriginalValuesKnown::Yes, StorageLocation::Database)
|
||||
.write_state(&outcome, OriginalValuesKnown::Yes, StorageLocation::Database)
|
||||
.expect("Could not write bundle state to DB");
|
||||
|
||||
let mut state = State::builder().with_bundle_update().build();
|
||||
@ -811,7 +814,7 @@ mod tests {
|
||||
let outcome: ExecutionOutcome =
|
||||
ExecutionOutcome::new(bundle, Receipts::default(), 1, Vec::new());
|
||||
provider
|
||||
.write_state(outcome, OriginalValuesKnown::Yes, StorageLocation::Database)
|
||||
.write_state(&outcome, OriginalValuesKnown::Yes, StorageLocation::Database)
|
||||
.expect("Could not write bundle state to DB");
|
||||
|
||||
let mut storage_changeset_cursor = provider
|
||||
@ -976,7 +979,7 @@ mod tests {
|
||||
let outcome =
|
||||
ExecutionOutcome::new(init_state.take_bundle(), Receipts::default(), 0, Vec::new());
|
||||
provider
|
||||
.write_state(outcome, OriginalValuesKnown::Yes, StorageLocation::Database)
|
||||
.write_state(&outcome, OriginalValuesKnown::Yes, StorageLocation::Database)
|
||||
.expect("Could not write bundle state to DB");
|
||||
|
||||
let mut state = State::builder().with_bundle_update().build();
|
||||
@ -1023,7 +1026,7 @@ mod tests {
|
||||
let outcome =
|
||||
ExecutionOutcome::new(state.take_bundle(), Receipts::default(), 1, Vec::new());
|
||||
provider
|
||||
.write_state(outcome, OriginalValuesKnown::Yes, StorageLocation::Database)
|
||||
.write_state(&outcome, OriginalValuesKnown::Yes, StorageLocation::Database)
|
||||
.expect("Could not write bundle state to DB");
|
||||
|
||||
let mut storage_changeset_cursor = provider
|
||||
|
||||
@ -108,14 +108,14 @@ where
|
||||
|
||||
// Write ommers if any
|
||||
if !body.ommers.is_empty() {
|
||||
ommers_cursor.append(block_number, StoredBlockOmmers { ommers: body.ommers })?;
|
||||
ommers_cursor.append(block_number, &StoredBlockOmmers { ommers: body.ommers })?;
|
||||
}
|
||||
|
||||
// Write withdrawals if any
|
||||
if let Some(withdrawals) = body.withdrawals {
|
||||
if !withdrawals.is_empty() {
|
||||
withdrawals_cursor
|
||||
.append(block_number, StoredBlockWithdrawals { withdrawals })?;
|
||||
.append(block_number, &StoredBlockWithdrawals { withdrawals })?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user