0

Example for my e-commerce site:

uint public PO;

function () {
    emit Purchase(PO++, msg.sender, msg.value, msg.data); // first param is indexed
}

The code above is for illustrative purpose only.

I have code listening to the Purchase event. May I know if the following possible?

  1. the Indexed PO value skipped some numbers because some of the transaction are rejected by the block chain?

  2. After receiving Purchase event at my listener, the transaction was rejected by blockchain?

  3. The PO+ was received out of order because some transactions were outgassed

Thanks dude

1 Answer 1

1

the Indexed PO value skipped some numbers because some of the transaction are rejected by the block chain?

If a transaction is rejected, it will not be mined at all, and thus won't increment PO to begin with. You should still receive them in order.

After receiving Purchase event at my listener, the transaction was rejected by blockchain?

This is possible if the block you were originally mined into is dropped. You can watch for this by looking for the removed: true field on the log events you receive. Note that if this does happen, the transaction will usually be mined into another block fairly soon, and your PO will still be in serial order.

The PO+ was received out of order because some transactions were outgassed

If the actual transaction's logic is identical to this, then you will still receive them in order, since the PO variable is only incremented on successful completion of a transaction.

4
  • Raghav, thanks for the answer. For the 2nd case, can I check the removed: true field immediately when I received the event? or have to check again a few minutes later to ensure that it is not removed?
    – s k
    Commented Aug 13, 2018 at 14:17
  • 1
    If you are filtering for the event, you will receive the event again with removed: true if the block is dropped Commented Aug 13, 2018 at 14:27
  • How long I shall wait before I check again, in order to be sure (or at least 99% sure) that the event will not be removed later?
    – s k
    Commented Aug 14, 2018 at 14:44
  • If you don't receive a removed event within the next 20 blocks or so, it's very reasonable to assume it's not being reverted Commented Aug 14, 2018 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.