Skip to content

Commit

Permalink
Hot fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauthamastro committed Feb 1, 2024
1 parent 917d0d8 commit 5ec3636
Show file tree
Hide file tree
Showing 4 changed files with 47 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 pallets/thea/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ pub mod pallet {
ErrorWhileReleasingLock(T::AccountId, DispatchError),
/// Misbehaviour Reported (fisherman, network, nonce)
MisbehaviourReported(T::AccountId, Network, u64),
/// New signature of Thea withdrawal
TheaSignatureUpdated(Network, u64, u16),
/// Signing completed
TheaSignatureFinalized(Network, u64),
}

#[pallet::error]
Expand Down Expand Up @@ -511,8 +515,17 @@ pub mod pallet {
let auth_len = <Authorities<T>>::get(signed_msg.validator_set_id).len();
if signed_msg.threshold_reached(auth_len) {
<SignedOutgoingNonce<T>>::insert(network, nonce);
// Emit an event
Self::deposit_event(Event::<T>::TheaSignatureFinalized(network, nonce));
}
let total_signatures = signed_msg.signatures.len();
<SignedOutgoingMessages<T>>::insert(network, nonce, signed_msg);
// Emit an event
Self::deposit_event(Event::<T>::TheaSignatureUpdated(
network,
nonce,
total_signatures as u16,
));
},
}
}
Expand Down Expand Up @@ -668,7 +681,7 @@ impl<T: Config> Pallet<T> {

ValidTransaction::with_tag_prefix("thea")
.and_provides(signatures)
.longevity(1)
.longevity(10)
.propagate(true)
.build()
}
Expand Down
39 changes: 28 additions & 11 deletions pallets/thea/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{
pallet::{ActiveNetworks, Authorities, OutgoingMessages, SignedOutgoingNonce, ValidatorSetId},
pallet::{
ActiveNetworks, Authorities, OutgoingMessages, SignedOutgoingMessages, SignedOutgoingNonce,
ValidatorSetId,
},
Call, Config, Pallet, THEA,
};
use frame_system::{offchain::SubmitTransaction, pallet_prelude::BlockNumberFor};
Expand Down Expand Up @@ -55,13 +58,25 @@ impl<T: Config> Pallet<T> {
log::info!(target: "thea", "Auth Index {:?} signer {:?}", auth_index, signer.clone());

let active_networks = <ActiveNetworks<T>>::get();
log::debug!(target:"thea","List of active networks: {:?}",active_networks);
log::info!(target:"thea","List of active networks: {:?}",active_networks);

let mut signed_messages: Vec<(Network, u64, T::Signature)> = Vec::new();
// 2. Check for new nonce to process for all networks
for network in active_networks {
// Sign message for each network
let next_outgoing_nonce = <SignedOutgoingNonce<T>>::get(network).saturating_add(1);
log::info!(target:"thea","Next outgoing nonce for network {:?} is: {:?} ",network, next_outgoing_nonce);
// Check if we already signed it, then continue
match <SignedOutgoingMessages<T>>::get(network, next_outgoing_nonce) {
None => {},
Some(signed_msg) => {
// Don't sign again if we already signed it
if signed_msg.contains_signature(&(*auth_index as u32)) {
log::warn!(target:"thea","Next outgoing nonce for network {:?} is: {:?} is already signed ",network, next_outgoing_nonce);
continue
}
},
}
let message = match <OutgoingMessages<T>>::get(network, next_outgoing_nonce) {
None => continue,
Some(msg) => msg,
Expand All @@ -74,16 +89,18 @@ impl<T: Config> Pallet<T> {
signed_messages.push((network, next_outgoing_nonce, signature.into()));
}

// we batch these signatures into a single extrinsic and submit on-chain
if let Err(()) = SubmitTransaction::<T, Call<T>>::submit_unsigned_transaction(
Call::<T>::submit_signed_outgoing_messages {
auth_index: *auth_index as u32,
id,
signatures: signed_messages,
if !signed_messages.is_empty() {
// we batch these signatures into a single extrinsic and submit on-chain
if let Err(()) = SubmitTransaction::<T, Call<T>>::submit_unsigned_transaction(
Call::<T>::submit_signed_outgoing_messages {
auth_index: *auth_index as u32,
id,
signatures: signed_messages,
}
.into(),
) {
log::error!(target:"thea","Error submitting thea unsigned txn");
}
.into(),
) {
log::error!(target:"thea","Error submitting thea unsigned txn");
}

log::debug!(target:"thea","Thea offchain worker exiting..");
Expand Down
2 changes: 1 addition & 1 deletion runtimes/mainnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// and set impl_version to 0. If only runtime
// implementation changes and behavior does not, then leave spec_version as
// is and increment impl_version.
spec_version: 318,
spec_version: 321,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
Expand Down

0 comments on commit 5ec3636

Please sign in to comment.