Skip to content

Commit 6d86c12

Browse files
committed
give each OCW a unique tx tag
1 parent 47367d6 commit 6d86c12

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

pallets/drand/src/lib.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ use frame_system::{
5151
};
5252
use scale_info::prelude::cmp;
5353
use sha2::{Digest, Sha256};
54+
use sp_core::blake2_256;
5455
use sp_runtime::{
5556
offchain::{http, Duration},
5657
traits::{Hash, One},
@@ -279,6 +280,7 @@ pub mod pallet {
279280
payload,
280281
signature,
281282
&payload.block_number,
283+
&payload.public,
282284
)
283285
}
284286
Call::write_pulse {
@@ -290,6 +292,7 @@ pub mod pallet {
290292
payload,
291293
signature,
292294
&payload.block_number,
295+
&payload.public,
293296
)
294297
}
295298
_ => InvalidTransaction::Call.into(),
@@ -506,16 +509,20 @@ impl<T: Config> Pallet<T> {
506509
payload: &impl SignedPayload<T>,
507510
signature: &T::Signature,
508511
block_number: &BlockNumberFor<T>,
512+
public: &T::Public,
509513
) -> TransactionValidity {
510514
let signature_valid =
511515
SignedPayload::<T>::verify::<T::AuthorityId>(payload, signature.clone());
512516
if !signature_valid {
513517
return InvalidTransaction::BadProof.into();
514518
}
515-
Self::validate_transaction_parameters(block_number)
519+
Self::validate_transaction_parameters(block_number, public)
516520
}
517521

518-
fn validate_transaction_parameters(block_number: &BlockNumberFor<T>) -> TransactionValidity {
522+
fn validate_transaction_parameters(
523+
block_number: &BlockNumberFor<T>,
524+
public: &T::Public,
525+
) -> TransactionValidity {
519526
// Now let's check if the transaction has any chance to succeed.
520527
let next_unsigned_at = NextUnsignedAt::<T>::get();
521528
if &next_unsigned_at > block_number {
@@ -527,6 +534,8 @@ impl<T: Config> Pallet<T> {
527534
return InvalidTransaction::Future.into();
528535
}
529536

537+
let provides_tag = (next_unsigned_at, public.encode()).using_encoded(blake2_256);
538+
530539
ValidTransaction::with_tag_prefix("DrandOffchainWorker")
531540
// We set the priority to the value stored at `UnsignedPriority`.
532541
.priority(T::UnsignedPriority::get())
@@ -538,7 +547,7 @@ impl<T: Config> Pallet<T> {
538547
// get to the transaction pool and will end up in the block.
539548
// We can still have multiple transactions compete for the same "spot",
540549
// and the one with higher priority will replace other one in the pool.
541-
.and_provides(next_unsigned_at)
550+
.and_provides(provides_tag)
542551
// The transaction is only valid for next block. After that it's
543552
// going to be revalidated by the pool.
544553
.longevity(1)

scripts/localnet.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ bob_start=(
9696
--allow-private-ipv4
9797
--discover-local
9898
--unsafe-force-node-key-generation
99-
--offchain-worker=Never
99+
# --offchain-worker=Never
100100
)
101101

102102
trap 'pkill -P $$' EXIT SIGINT SIGTERM

0 commit comments

Comments
 (0)