Browse Source

Removed second "SLEEP_UNTIL_MESSAGE" function code call in LitecoinACCTv3 and DogecoinACCTv3.

It turns out that when you call SLEEP_UNTIL_MESSAGE, the AT resumes from that very same line on the next execution. The original code incorrectly assumed that it would execute from the restart position (SET_PCS).

So sleeping can be thought of as pausing one execution half way through, rather than ending it.

This caused a bug, because once the AT receives a transaction it wakes up and resumes from the SLEEP_UNTIL_MESSAGE line, which is after the refund check. Even when it loops back around again it lands on labelRedeemTxnLoop = codeByteBuffer.position(); which is again after the refund check.

For now, the simplest fix is to only sleep when listed. We could have alternatively moved the SLEEP_UNTIL_MESSAGE above GET_BLOCK_TIMESTAMP, but this would still require users to send a random transaction to the AT to trigger the refund. Given that the ATs are only "alive" for 30 minutes once the trade begins, it's simpler to just execute every block and therefore allow the refunds to happen automatically.
protoniuman-FR-patch-1
CalDescent 3 years ago
parent
commit
f52bafc014
  1. 5
      src/main/java/org/qortal/crosschain/DogecoinACCTv3.java
  2. 5
      src/main/java/org/qortal/crosschain/LitecoinACCTv3.java

5
src/main/java/org/qortal/crosschain/DogecoinACCTv3.java

@ -88,7 +88,7 @@ public class DogecoinACCTv3 implements ACCT {
private static final Logger LOGGER = LogManager.getLogger(DogecoinACCTv3.class); private static final Logger LOGGER = LogManager.getLogger(DogecoinACCTv3.class);
public static final String NAME = DogecoinACCTv3.class.getSimpleName(); public static final String NAME = DogecoinACCTv3.class.getSimpleName();
public static final byte[] CODE_BYTES_HASH = HashCode.fromString("6fff38d6eeb06568a9c879c5628527730319844aa0de53f5f4ffab5506efe885").asBytes(); // SHA256 of AT code bytes public static final byte[] CODE_BYTES_HASH = HashCode.fromString("03b44087f6325463eb745aa32d9a782add03148bcfbe73ffd8854ce55ff863d4").asBytes(); // SHA256 of AT code bytes
public static final int SECRET_LENGTH = 32; public static final int SECRET_LENGTH = 32;
@ -465,9 +465,6 @@ public class DogecoinACCTv3 implements ACCT {
/* Transaction processing loop */ /* Transaction processing loop */
labelRedeemTxnLoop = codeByteBuffer.position(); labelRedeemTxnLoop = codeByteBuffer.position();
/* Sleep until message arrives */
codeByteBuffer.put(OpCode.EXT_FUN_DAT.compile(QortalFunctionCode.SLEEP_UNTIL_MESSAGE.value, addrLastTxnTimestamp));
// Find next transaction to this AT since the last one (if any) // Find next transaction to this AT since the last one (if any)
codeByteBuffer.put(OpCode.EXT_FUN_DAT.compile(FunctionCode.PUT_TX_AFTER_TIMESTAMP_INTO_A, addrLastTxnTimestamp)); codeByteBuffer.put(OpCode.EXT_FUN_DAT.compile(FunctionCode.PUT_TX_AFTER_TIMESTAMP_INTO_A, addrLastTxnTimestamp));
// If no transaction found, A will be zero. If A is zero, set addrComparator to 1, otherwise 0. // If no transaction found, A will be zero. If A is zero, set addrComparator to 1, otherwise 0.

5
src/main/java/org/qortal/crosschain/LitecoinACCTv3.java

@ -84,7 +84,7 @@ import static org.ciyam.at.OpCode.calcOffset;
public class LitecoinACCTv3 implements ACCT { public class LitecoinACCTv3 implements ACCT {
public static final String NAME = LitecoinACCTv3.class.getSimpleName(); public static final String NAME = LitecoinACCTv3.class.getSimpleName();
public static final byte[] CODE_BYTES_HASH = HashCode.fromString("d5ea386a41441180c854ca8d7bbc620bfd53a97df2650a2b162b52324caf6e19").asBytes(); // SHA256 of AT code bytes public static final byte[] CODE_BYTES_HASH = HashCode.fromString("31588e7ddb95a908bce310bb6dc76f011ff4693d2f8a3741fab3c989d56ce7c7").asBytes(); // SHA256 of AT code bytes
public static final int SECRET_LENGTH = 32; public static final int SECRET_LENGTH = 32;
@ -458,9 +458,6 @@ public class LitecoinACCTv3 implements ACCT {
/* Transaction processing loop */ /* Transaction processing loop */
labelRedeemTxnLoop = codeByteBuffer.position(); labelRedeemTxnLoop = codeByteBuffer.position();
/* Sleep until message arrives */
codeByteBuffer.put(OpCode.EXT_FUN_DAT.compile(QortalFunctionCode.SLEEP_UNTIL_MESSAGE.value, addrLastTxnTimestamp));
// Find next transaction to this AT since the last one (if any) // Find next transaction to this AT since the last one (if any)
codeByteBuffer.put(OpCode.EXT_FUN_DAT.compile(FunctionCode.PUT_TX_AFTER_TIMESTAMP_INTO_A, addrLastTxnTimestamp)); codeByteBuffer.put(OpCode.EXT_FUN_DAT.compile(FunctionCode.PUT_TX_AFTER_TIMESTAMP_INTO_A, addrLastTxnTimestamp));
// If no transaction found, A will be zero. If A is zero, set addrComparator to 1, otherwise 0. // If no transaction found, A will be zero. If A is zero, set addrComparator to 1, otherwise 0.

Loading…
Cancel
Save