Skip to content

Commit d37bdc7

Browse files
committed
docs: document race condition in insert_aggregated_payload
Add thread safety documentation to insert_aggregated_payload method to clarify the non-atomic read-modify-write pattern. This method reads existing payloads, appends a new one, and writes back. Concurrent calls could result in lost updates. The method must be called from a single thread. In ethlambda's architecture, the BlockChain actor (GenServer pattern) provides single-threaded access.
1 parent c62b9fe commit d37bdc7

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

crates/storage/src/store.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,21 @@ impl Store {
785785
})
786786
}
787787

788+
/// Insert an aggregated signature proof for a validator's attestation.
789+
///
790+
/// Multiple proofs can be stored for the same (validator, attestation_data) pair,
791+
/// each with its own slot metadata for pruning.
792+
///
793+
/// # Thread Safety
794+
///
795+
/// This method uses a read-modify-write pattern that is NOT atomic:
796+
/// 1. Read existing payloads
797+
/// 2. Append new payload
798+
/// 3. Write back
799+
///
800+
/// Concurrent calls could result in lost updates. This method MUST be called
801+
/// from a single thread. In ethlambda, the Store is owned by the BlockChain
802+
/// actor which provides single-threaded access.
788803
pub fn insert_aggregated_payload(
789804
&mut self,
790805
attestation_data: &AttestationData,
@@ -795,7 +810,7 @@ impl Store {
795810
let data_root = attestation_data.tree_hash_root();
796811
let key = (validator_id, data_root);
797812

798-
// Read existing, add new, write back
813+
// Read existing, add new, write back (NOT atomic - requires single-threaded access)
799814
let mut payloads = self.get_aggregated_payloads(&key).unwrap_or_default();
800815
payloads.push(StoredAggregatedPayload { slot, proof });
801816

0 commit comments

Comments
 (0)