Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
bc28c60
Add documentation to signed transactions and actually make them work.
tomusdrw Nov 25, 2019
a645b90
Fix naming and bounds.
tomusdrw Nov 25, 2019
f8c9540
Forgotten import.
tomusdrw Nov 25, 2019
f85b890
Merge branch 'master' into td-signed-transactions
tomusdrw Dec 2, 2019
3f38218
Merge branch 'master' into td-signed-transactions
tomusdrw Dec 3, 2019
d715f64
Remove warning.
tomusdrw Dec 3, 2019
0c4c037
Make accounts optional, fix logic.
tomusdrw Dec 3, 2019
dc8d71c
Split the method to avoid confusing type error message.
tomusdrw Dec 3, 2019
173cf6c
Move executor tests to integration.
tomusdrw Nov 28, 2019
90a00fd
Add submit transactions tests.
tomusdrw Dec 3, 2019
901dbdb
Merge branch 'master' into td-signed-transactions
tomusdrw Dec 10, 2019
d103fa1
Make `submit_transaction` tests compile
HCastano Dec 19, 2019
99c54b7
Remove a file that was accidently committed
HCastano Dec 19, 2019
dbc81dd
Merge branch 'master' into td-signed-transactions
tomusdrw Dec 20, 2019
9eb7a2e
Add can_sign helper function.
tomusdrw Dec 20, 2019
0ccb951
Fix compilation.
tomusdrw Dec 20, 2019
73a936c
Add a key to keystore.
tomusdrw Dec 20, 2019
d776d50
Fix the tests.
tomusdrw Dec 20, 2019
0ac61d7
Remove env_logger.
tomusdrw Dec 20, 2019
8755539
Fix sending multiple transactions.
tomusdrw Dec 20, 2019
fc6b5fe
Remove commented code.
tomusdrw Dec 20, 2019
af1782e
Bring back criterion.
tomusdrw Dec 20, 2019
58673bf
Merge branch 'master' into td-signed-transactions
tomusdrw Dec 23, 2019
bacf48c
Remove stray debug log.
tomusdrw Dec 23, 2019
b3c8726
Merge branch 'master' into td-signed-transactions
gavofyork Jan 3, 2020
da816e2
Apply suggestions from code review
tomusdrw Jan 6, 2020
a2c6d09
Make sure to initialize block correctly.
tomusdrw Jan 8, 2020
af5724c
Initialize block for offchain workers.
tomusdrw Jan 8, 2020
3eda535
Add test for transaction validity.
tomusdrw Jan 8, 2020
765f96f
Merge branch 'master' into td-signed-transactions
tomusdrw Jan 8, 2020
6bafaff
Fix tests.
tomusdrw Jan 8, 2020
021f586
Review suggestions.
tomusdrw Jan 8, 2020
3ac00ff
Remove redundant comment.
tomusdrw Jan 8, 2020
7f38d4c
Make sure to use correct block number of authoring.
tomusdrw Jan 8, 2020
afb99f9
Change the runtime API.
tomusdrw Jan 9, 2020
a945a8c
Support both versions.
tomusdrw Jan 9, 2020
4c66a45
Bump spec version, fix RPC test.
tomusdrw Jan 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Support both versions.
  • Loading branch information
tomusdrw committed Jan 9, 2020
commit a945a8c39b961e179d2592c04931e7f9030a1d54
4 changes: 2 additions & 2 deletions bin/node/executor/tests/submit_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

use node_runtime::{
Call, Executive, Indices, Balances, Runtime, SubmitTransaction, UncheckedExtrinsic,
Call, Executive, Indices, Runtime, SubmitTransaction, UncheckedExtrinsic,
};
use sp_application_crypto::AppKey;
use sp_core::testing::KeyStore;
Expand Down Expand Up @@ -139,7 +139,7 @@ fn submitted_transaction_should_be_valid() {
use codec::Encode;
use frame_support::storage::StorageMap;
use sp_runtime::transaction_validity::ValidTransaction;
use sp_runtime::traits::{Dispatchable, StaticLookup};
use sp_runtime::traits::StaticLookup;

let mut t = new_test_ext(COMPACT_CODE, false);
let (pool, state) = TestTransactionPoolExt::new();
Expand Down
7 changes: 3 additions & 4 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,9 @@ impl frame_system::offchain::CreateTransaction<Runtime, UncheckedExtrinsic> for
.unwrap_or(2) as u64;
let current_block = System::block_number()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realized, you skip initialize_block when calling offchain_worker. This means, that block_number() always returns 0.

.saturated_into::<u64>()
// The `System::block_number` is initialized with `n+1`, so the actual block number is
// `n`, but in offchain worker context this block does not have correct `parent_hash` set,
// so we need to fall back to `n-1`.
.saturating_sub(2);
// The `System::block_number` is initialized with `n+1`,
// so the actual block number is `n`.
.saturating_sub(1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not build on the current block?

let tip = 0;
let extra: SignedExtra = (
frame_system::CheckVersion::<Runtime>::new(),
Expand Down
33 changes: 23 additions & 10 deletions client/offchain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,18 @@ impl<Client, Storage, Block> OffchainWorkers<
) -> impl Future<Output = ()> {
let runtime = self.client.runtime_api();
let at = BlockId::number(*header.number());
// TODO [ToDr] Use has_api_with to support old versions too
let has_api = runtime.has_api::<dyn OffchainWorkerApi<Block, Error = ()>>(&at);
debug!("Checking offchain workers at {:?}: {:?}", at, has_api);

if has_api.unwrap_or(false) {
let has_api_v1 = runtime.has_api_with::<dyn OffchainWorkerApi<Block, Error = ()>, _>(
&at, |v| v == 1
);
let has_api_v2 = runtime.has_api::<dyn OffchainWorkerApi<Block, Error = ()>>(&at);
let version = match (has_api_v1, has_api_v2) {
(_, Ok(true)) => 2,
(Ok(true), _) => 1,
_ => 0,
};

debug!("Checking offchain workers at {:?}: version:{}", at, version);
if version > 0 {
let (api, runner) = api::AsyncApi::new(
self.db.clone(),
network_state.clone(),
Expand All @@ -115,11 +122,17 @@ impl<Client, Storage, Block> OffchainWorkers<
let runtime = client.runtime_api();
let api = Box::new(api);
debug!("Running offchain workers at {:?}", at);
let run = runtime.offchain_worker_with_context(
&at,
ExecutionContext::OffchainCall(Some((api, offchain::Capabilities::all()))),
&header,
);
let context = ExecutionContext::OffchainCall(Some(
(api, offchain::Capabilities::all())
));
let run = if version == 2 {
runtime.offchain_worker_with_context(&at, context, &header)
} else {
#[allow(deprecated)]
runtime.offchain_worker_before_version_2_with_context(
&at, context, *header.number()
)
};
if let Err(e) = run {
log::error!("Error running offchain workers at {:?}: {:?}", at, e);
}
Expand Down