Random.Blob() Broken

Hi there,

My code has not been updated in month and for some reason it has suddenly broken lol.

I have found the line causing the issue

let memo = await Random.blob();

I am getting this error in response

Server returned an error:
  Code: 400 (Bad Request)
  Body: Invalid signature: Invalid basic signature: Ed25519 signature could not be verified: public key e9de264ff18e7faaf551b7bbbab85affed592b82643796abef20f1ff6b5ac9a3, signature 8f92f2f70c22e4bb422c16e8d46c6297391ad8698f6342ae5c8546f0b48c807dd88fdc34da291494f4e5fd03f30fbdaea750784c44fb5a6d7e6152015cc82903, error: A signature was invalid

please can someone at Dfinity have a look into this urgently

1 Like

That does not look like a Motoko error. Where are you getting this error? Is this a response produced by an agent?

I was using the memo to transfer funds


ICRC.service(Constants.CKBTC_Canister).icrc1_transfer(_transferArgsFactory(amount, fee, user, memo));

Because the one thing that has changed is that i am now using the ckBTC canister rather than ICP canister

If i put memo as null it works fine

Or if i set memo to this it also works fine

let memo : Blob = Blob.fromArray([1, 2, 3, 4, 5]);

I don’t know if its also worth mentioning that once i receive this error from the canister and I try to redeploy the canister (without using --mode reinstall) i get this error:

Error: Failed while trying to deploy canisters.
Caused by: Failed while trying to install all canisters.
Caused by: Failed to install wasm module to canister 'orderbook'.
Caused by: Failed during wasm installation call
Caused by: The replica returned a rejection error: reject code CanisterError, reject message Error from Canister i6gc2-jaaaa-aaaag-ak5dq-cai: Canister called `ic0.trap` with message: canister_pre_upgrade attempted with outstanding message callbacks (try stopping the canister before upgrade)
Canister Backtrace:
unknown function at index 685
.
Consider gracefully handling failures from this canister or altering the canister to handle exceptions. See documentation: http://internetcomputer.org/docs/current/references/execution-errors#trapped-explicitly, error code None

I have created this script

async function main() {
  try {
    const icblastModule = await import('@infu/icblast');
    const { default: icblast, hashIdentity } = icblastModule;

    const canisterID = 'jtigu-giaaa-aaaag-ak5ea-cai';

    const hash = 'game-controller-development';
    const identity = hashIdentity(hash);

    const principal = identity.getPrincipal().toString();

    const ic = icblast({ identity: identity });

    let actor = await ic(canisterID, idlFactory);
    const admins = await actor.getAdmins();
    console.log(admins);

    const endEventData = await actor.panicEvent();
    console.log(endEventData);
  } catch (error) {
    console.error('Error:', error);
  }
}

main();

The first call works completely fine to get admins but the second call fails

I also tried with a different type of update call and it works perfectly fine

Also when i use the dfx cli it works as expect it only fails when i am using an actor call using the dfinity agent

Could it be related to a Timeout?

It is failing here

 let transferResults = await Payments.payUsers(transfersMap, market.id);
  public shared ({ caller }) func panicEvent() : async T.EventEndData {
    await* _isAdmin(caller);
    for ((marketId, market) in Map.entries(markets)) {
      market.orderBook.state := #Finishing;
    };

    var marketTransferResults = Buffer.Buffer<T.MarketTransferResult>(0);

    for (market in Map.vals(markets)) {
      let transfersMap : T.TransfersMap = Map.new();
      await Orders.getTransferAmounts(market, null, orders, transfersMap, accounting, Utils.isNftHolder, nftMap);
      // let res : T.SuccessfulTransfer = {
      //   user = Principal.fromText("wkvns-5prta");
      //   marketId = market.id;
      //   amount = 0;
      // };
      // let transferResults = [#Ok(res)];
      let transferResults = await Payments.payUsers(transfersMap, market.id);

      marketTransferResults.add({
        marketId = market.id;
        transferResults = #Ok(transferResults);
      });
      market.orderBook.state := #Cancelled;
    };
    await Orchestrator.service(env.orchestrator).removeFromCurrentUserBetCanisters();
    // let endEventData : T.EventEndData = {
    //   canisterId = Principal.fromText("wkvns-5prta");
    //   eventId = 1;
    //   endTime = 1000000;
    //   totalCommissions = 1;
    //   totalMatched = 1;
    //   totalOpen = 1;
    //   marketAccounting = [];
    //   transferResults = [];
    //   createdBets = [];
    //   matchedBets = [];
    // };
    // return endEventData
    Portfolio.generateEndEventData(Principal.fromActor(this), id, markets, orders, accounting, Map.new(), Buffer.toArray(marketTransferResults), nftMap);
  };


payments.mo

  public func payUsers(transfersMap : T.TransfersMap, marketId : T.MarketID) : async [T.TransferResult] {
    // let transferResults = Buffer.Buffer<T.TransferResult>(Map.size(transfersMap));
    // let fee = await* getFee();
    // for ((user, amount) in Map.entries(transfersMap)) {
    //   transferResults.add(await transferFunds(user, Utils.normaliseBtcAmount(amount), fee, marketId));
    // };

    let res : T.SuccessfulTransfer = {
      user = Principal.fromText("wkvns-5prta");
      marketId = marketId;
      amount = 0;
    };
    let transferResults = [#Ok(res)];

    return transferResults;
  };

I have been getting this error too when running dfx locally. The function that is producing this error also involves both calls to Random.blob() and the ICRC1 transfer function. It only happens on occasion so I have just been hoping it has something to do with fetchRootKey or just local internet identity in general so have just been ignoring it hoping that it will not occur when I deploy to mainnet.

What leads you to believe that Random.blob() is the culprit?

I have changed my mind. I dont think it is Random blob that is the culprit i just think it is calls that take a long time to execute so a time out error. I am also seeing this error on mainnet

1 Like