Fix for off-by-one bug when ATs look for next transaction. Currently configured to take effect block 275,000

This commit is contained in:
catbref 2021-01-17 16:01:36 +00:00
parent e5bb3e2f0a
commit d336200d75
4 changed files with 23 additions and 5 deletions

View File

@ -146,7 +146,11 @@ public class QortalATAPI extends API {
String atAddress = this.atData.getATAddress();
int height = timestamp.blockHeight;
int sequence = timestamp.transactionSequence + 1;
int sequence = timestamp.transactionSequence;
if (state.getCurrentBlockHeight() < BlockChain.getInstance().getAtFindNextTransactionFixHeight())
// Off-by-one bug still in effect
sequence += 1;
ATRepository.NextTransactionInfo nextTransactionInfo;
try {

View File

@ -70,6 +70,7 @@ public class BlockChain {
private GenesisBlock.GenesisInfo genesisInfo;
public enum FeatureTrigger {
atFindNextTransactionFix;
}
/** Map of which blockchain features are enabled when (height/timestamp) */
@ -371,6 +372,10 @@ public class BlockChain {
// Convenience methods for specific blockchain feature triggers
public int getAtFindNextTransactionFixHeight() {
return this.featureTriggers.get(FeatureTrigger.atFindNextTransactionFix.name()).intValue();
}
// More complex getters for aspects that change by height or timestamp
public long getRewardAtHeight(int ourHeight) {

View File

@ -48,6 +48,7 @@
"minutesPerBlock": 1
},
"featureTriggers": {
"atFindNextTransactionFix": 275000
},
"genesisInfo": {
"version": 4,

View File

@ -77,16 +77,24 @@ public class GetNextTransactionTests extends Common {
BlockUtils.mintBlock(repository);
assertTimestamp(repository, atAddress, transaction);
// Mint a few blocks, then send non-AT message, followed by AT message
// Mint a few blocks, then send non-AT message, followed by two AT messages (in same block)
for (int i = 0; i < 5; ++i)
BlockUtils.mintBlock(repository);
sendMessage(repository, deployer, data, deployer.getAddress());
transaction = sendMessage(repository, deployer, data, atAddress);
Transaction transaction1 = sendMessage(repository, deployer, data, atAddress);
Transaction transaction2 = sendMessage(repository, deployer, data, atAddress);
BlockUtils.mintBlock(repository);
// Confirm AT finds message
// Confirm AT finds first message
BlockUtils.mintBlock(repository);
assertTimestamp(repository, atAddress, transaction);
assertTimestamp(repository, atAddress, transaction1);
// Confirm AT finds second message
BlockUtils.mintBlock(repository);
assertTimestamp(repository, atAddress, transaction2);
}
}