Skip to content

Commit

Permalink
Fix app stale at sending extrinsics aka fix occasional invalid extrin…
Browse files Browse the repository at this point in the history
…sic (#1665)

* [tx] log extrinsic update value, which might contain information about the invalid error

* [tx] immediately refresh encointer balance and reputations after claiming rewards

* [tx_builder] ensure that block number and block hash are corresponding to the same block

* [tx_builder] construct extrinsic based on finalized block data
  • Loading branch information
clangenb authored Mar 20, 2024
1 parent c00a338 commit 5eac022
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/lib/service/tx/lib/src/send_tx_dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class EWAuthorApi<P extends Provider> {
String? blockHashHex;

final sub = await submitAndWatchExtrinsic(extrinsic, (xtUpdate) async {
Log.d('ExtrinsicUpdate: ${xtUpdate.type}');
Log.d('ExtrinsicUpdate: type: ${xtUpdate.type}, value: ${xtUpdate.value}');

if (xtUpdate.type == 'ready') {
Log.p('Xt is ready');
Expand Down
3 changes: 2 additions & 1 deletion app/lib/service/tx/lib/src/submit_tx_wrappers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ Future<void> submitClaimRewards(
onFinish: (BuildContext txPageContext, ExtrinsicReport report) {
// Claiming the rewards creates a new reputation if successful.
// Hence, we should update the state afterwards.
store.dataUpdate.setInvalidated();
store.encointer.getEncointerBalance();
webApi.encointer.getReputations();
return report;
},
);
Expand Down
17 changes: 12 additions & 5 deletions app/lib/service/tx/lib/src/tx_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class TxBuilder {

// fetch recent relevant data from chain
final runtimeVersion = await _getRuntimeVersion();
final blockNumber = await _getBlockNumber();
final blockHash = await _getBlockHash();
final finalizedHash = await _getLatestFinalizedHash();
final blockNumber = await _getBlockNumber(hash: finalizedHash);
final genesisHash = await _getBlockHash(blockNumber: 0);
final accountInfo = await encointerKusama.query.system.account(pair.publicKey.bytes);

Expand All @@ -49,7 +49,7 @@ class TxBuilder {
specVersion: runtimeVersion.specVersion,
transactionVersion: runtimeVersion.transactionVersion,
genesisHash: genesisHash,
blockHash: blockHash,
blockHash: finalizedHash,
blockNumber: blockNumber,
eraPeriod: 64,
nonce: accountInfo.nonce,
Expand Down Expand Up @@ -85,8 +85,15 @@ class TxBuilder {
return hash.replaceFirst('0x', '');
}

Future<int> _getBlockNumber() async {
final block = await provider.send('chain_getBlock', []);
Future<String> _getLatestFinalizedHash() async {
final hash = (await provider.send('chain_getFinalizedHead', [])).result as String;
return hash.replaceFirst('0x', '');
}

Future<int> _getBlockNumber({String? hash}) async {
final params = hash != null ? [hash.replaceFirst('0x', '')] : <String>[];

final block = await provider.send('chain_getBlock', params);

// ignore: avoid_dynamic_calls
final blockNumber = int.parse(block.result['block']['header']['number'] as String);
Expand Down

0 comments on commit 5eac022

Please sign in to comment.