Search code examples
c#ethereumtask-parallel-library

Task Status Confusion - WaitingForActivation


I’m having trouble understanding a TPL related issue about my task’s status with an asynchronous method I’m trying run and hoping someone can point me in the right direction. I’m using a method from the Nethereum library called SendTransactionAndWaitForReceiptAsync to send a transaction to the Ethereum network, and it returns a Task object. As part of a timeout mechanism, I also have a Task representing a timer. See below.

var nonce = await web3.Eth.Transactions.GetTransactionCount.SendRequestAsync(account.Address);
var input = new TransactionInput()
    {
        Nonce = nonce.Value.ToHexBigInteger()
        //Plus other necessary data
    };

var transactionTask = web3.Eth.TransactionManager.SendTransactionAndWaitForReceiptAsync(input);
var timeoutTask = Task.Delay(60000);
var completedTask = await Task.WhenAny(transactionTask, timeoutTask);
Console.WriteLine($"status = {transactionTask.Status}");

Output as follows:

//If nonce is incorrect value (higher)
status = WaitingForActivation
//If nonce is correct value
status = RanToCompletion

My confusion here is that if the nonce value is correct for my transaction, the task completes first with a RanToCompletion status. But if I deliberately provide an incorrect nonce (noce + 1), it stays on the WaitingForActivation status despite threads being available. But surely it should be in the Running status? The Task must’ve at least been scheduled and started running despite one of the parameters (nonce) being incorrect (too high). The transaction clearly moves out of the WaitingForActivation status if the nonce value is correct, but not if it's incorrect. The method should still execute, and I'm pretty sure it does since I know that if the nonce value is too high, the method executes and the transaction will be queued in the Ethereum network. But why is the Task status telling me it's yet to be executed or even allocated a thread?

I’m certainly open to the idea that my understanding and use of TPL is what’s causing my confusion.


Solution

  • Running is not a valid state for Promise Tasks (i.e., asynchronous tasks).

    In this case, "waiting for activation" does mean "in progress" or "not complete". It just means the asynchronous work hasn't completed yet.