DataHighway-DHX / node

DataHighway Node. A blockchain being built with Substrate to become a parachain on the Polkadot network. Planned features include a decentralized LPWAN roaming hub for LoRaWAN IoT devices and network operator roaming agreements, participative mining, an inter-chain data market, and DAO governance. http://www.datahighway.com
http://www.datahighway.com
GNU General Public License v3.0
51 stars 10 forks source link

feat: MMD-1309 10-to-1 - Off-chain workers #238

Open ltfschoen opened 2 years ago

ltfschoen commented 2 years ago

i had it working in mock.rs with type AccountId = u128

impl frame_system::Config for Test {
    ...
    type AccountId = AccountId;
...

but now i have to update mock.rs so it works with off-chain workers, but i'm not sure how to get it to work.

in frame example-offchain-workers AccountId is:

impl frame_system::Config for Test {
        ...
    type AccountId = sp_core::sr25519::Public;
...

(as shown here: https://github.com/paritytech/substrate/blob/master/frame/example-offchain-worker/src/tests.rs#L67 )

where AccountId is:

type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;

(as shown here: https://github.com/paritytech/substrate/blob/master/frame/example-offchain-worker/src/tests.rs#L83)

and it uses <Signature as Verify>::Signer in these two places:

so far the changes i've made are in this PR in the file pallets/mining/rewards-allowance/src/mock.rs here: https://github.com/DataHighway-DHX/node/pull/238/files#diff-b7ace9b0e8a1d800ea987e0e9b9e117f8fe6a52b923a9e654b65495c90c7ffd5R468

and when i run the tests with cargo test -p mining-rewards-allowance, i get the following error:

error[E0271]: type mismatch resolving `<sp_core::sr25519::Public as IdentifyAccount>::AccountId == u128`
   --> pallets/mining/rewards-allowance/src/mock.rs:449:2
    |
449 |     type Public = <Signature as Verify>::Signer;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u128`, found struct `sp_core::sr25519::Public`
    |
note: required by a bound in `frame_system::offchain::SigningTypes::Public`
   --> /Users/ls2/.cargo/git/checkouts/substrate-f10629da2328b525/f5dc02a/frame/system/src/offchain.rs:453:21
    |
453 |         + IdentifyAccount<AccountId = Self::AccountId>
    |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `frame_system::offchain::SigningTypes::Public`

SOLUTION: This was fixed in this commit 9ad33cdf615e54699613d608134cae5c89dcc3ab

so instead we should be providing the date that the account id's mpower relates to from the API with a timestamp, and then in offchain_workers figure out the start of that date, and store it.

Note: See Jira mPower MMD-1584 for latest status