Skip to content

Commit

Permalink
Apollo Blockchain 1.47.28 Hotfix Release
Browse files Browse the repository at this point in the history
Merge pull request #1177 from ApolloFoundation/stage 
Less strict overflow validation for confirmed tx
  • Loading branch information
AndrewBoyarsky committed Sep 6, 2021
2 parents 593326f + 9e47b1e commit 036ff65
Show file tree
Hide file tree
Showing 23 changed files with 119 additions and 95 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.47.27
1.47.28
2 changes: 1 addition & 1 deletion apl-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.apollocurrency</groupId>
<artifactId>apollo-blockchain</artifactId>
<version>1.47.27</version>
<version>1.47.28</version>
</parent>

<artifactId>apl-api</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion apl-api2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.apollocurrency</groupId>
<artifactId>apollo-blockchain</artifactId>
<version>1.47.27</version>
<version>1.47.28</version>
</parent>

<artifactId>apl-api2</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion apl-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.apollocurrency</groupId>
<artifactId>apl-bom</artifactId>
<version>1.47.27</version>
<version>1.47.28</version>
<packaging>pom</packaging>
<name>apl-bom</name>

Expand Down
2 changes: 1 addition & 1 deletion apl-conf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.apollocurrency</groupId>
<artifactId>apollo-blockchain</artifactId>
<version>1.47.27</version>
<version>1.47.28</version>
</parent>
<artifactId>apl-conf</artifactId>
<name>apl-conf</name>
Expand Down
2 changes: 2 additions & 0 deletions apl-conf/src/main/resources/conf/chains.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
7882427, 7882426, 7468092, 7468091, 7460076, 7460075, 7452190, 7452189, 7417594, 7417593,
7400635, 7400634, 7344893, 7344892, 7313652, 7313651, 7312320, 7312319, 7308462, 7308461,
7308278, 7308277, 7304669, 7304670, 6518814, 6518815],
"totalAmountOverflowTxs": ["3309980870150352112", "10328829363764104064", "11704807913978762684", "17412335979875507223",
"10627452365145084128", "14016156183641621536", "10832252742068911551"],
"blockchainProperties": [
{
"height": 0,
Expand Down
2 changes: 1 addition & 1 deletion apl-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.apollocurrency</groupId>
<artifactId>apollo-blockchain</artifactId>
<version>1.47.27</version>
<version>1.47.28</version>
</parent>
<artifactId>apl-core</artifactId>
<name>apl-core</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ public boolean isCurrencyIssuanceHeight(int height) {
return chain.getCurrencyIssuanceHeights() != null && chain.getCurrencyIssuanceHeights().contains(height);
}

public boolean isTotalAmountOverflowTx(long id) {
return chain.getTotalAmountOverflowTxs() != null && chain.getTotalAmountOverflowTxs().contains(Long.toUnsignedString(id));
}

public Integer getDexPendingOrdersReopeningHeight() {
if (chain.getFeaturesHeightRequirement() != null) {
return chain.getFeaturesHeightRequirement().getDexReopenPendingOrdersHeight();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ public void doStateIndependentValidation(Transaction transaction) throws AplExce
|| attachment.getAssetId() == 0) {
throw new AplException.NotValidException("Invalid asset order placement: " + attachment.getJSONObject());
}
long orderTotalATM = Convert2.safeMultiply(attachment.getQuantityATU(), attachment.getPriceATM(), transaction);
if (orderTotalATM > maxBalanceATM) {
throw new AplException.NotValidException("Order total in ATMs " + orderTotalATM
+ " is greater than max allowed: " + maxBalanceATM
+ ", asset=" + Long.toUnsignedString(attachment.getAssetId()) + ", quantity="
+ attachment.getQuantityATU() + ", price=" + attachment.getPriceATM());
if (!getBlockchainConfig().isTotalAmountOverflowTx(transaction.getId())) {
long orderTotalATM = Convert2.safeMultiply(attachment.getQuantityATU(), attachment.getPriceATM(), transaction);
if (orderTotalATM > maxBalanceATM) {
throw new AplException.NotValidException("Order total in ATMs " + orderTotalATM
+ " is greater than max allowed: " + maxBalanceATM
+ ", asset=" + Long.toUnsignedString(attachment.getAssetId()) + ", quantity="
+ attachment.getQuantityATU() + ", price=" + attachment.getPriceATM());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ public void doStateIndependentValidation(Transaction transaction) throws AplExce
if (attachment.getRateATM() <= 0 || attachment.getUnits() == 0) {
throw new AplException.NotValidException("Invalid exchange: " + attachment.getJSONObject());
}
long orderTotalATM = Convert2.safeMultiply(attachment.getRateATM(), attachment.getUnits(), transaction);
long maxBalanceATM = getBlockchainConfig().getCurrentConfig().getMaxBalanceATM();
if (orderTotalATM > maxBalanceATM) {
throw new AplException.NotValidException("Currency order total in ATMs: " + orderTotalATM + " is higher than max allowed: "
+ maxBalanceATM + ", currency=" + Long.toUnsignedString(attachment.getCurrencyId()) + ", quantity="
+ attachment.getUnits() + ", price=" + attachment.getRateATM());
if (!getBlockchainConfig().isTotalAmountOverflowTx(transaction.getId())) {
long orderTotalATM = Convert2.safeMultiply(attachment.getRateATM(), attachment.getUnits(), transaction);
long maxBalanceATM = getBlockchainConfig().getCurrentConfig().getMaxBalanceATM();
if (orderTotalATM > maxBalanceATM) {
throw new AplException.NotValidException("Currency order total in ATMs: " + orderTotalATM + " is higher than max allowed: "
+ maxBalanceATM + ", currency=" + Long.toUnsignedString(attachment.getCurrencyId()) + ", quantity="
+ attachment.getUnits() + ", price=" + attachment.getRateATM());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class BlockchainConfigTest {
"Test",
10000L, 2,
//"data.json",
BLOCKCHAIN_PROPERTIES, new FeaturesHeightRequirement(100, 100, 100), Set.of(20, 21, 25, 26));
BLOCKCHAIN_PROPERTIES, new FeaturesHeightRequirement(100, 100, 100), Set.of(20, 21, 25, 26), Set.of("1000", "18446744073709551615"));
@Inject
BlockchainConfig blockchainConfig;
@Inject
Expand Down Expand Up @@ -94,6 +94,19 @@ void testInitBlockchainConfigForFeatureHeightRequirement() {
assertNull(blockchainConfig.getDexPendingOrdersReopeningHeight());
}

@Test
void testInitBlockchainConfigForCurrencySellTxs() {
blockchainConfig.updateChain(chain);

assertTrue(blockchainConfig.isTotalAmountOverflowTx(1000), "Transaction with id 1000 should be a currency sell tx");
assertTrue(blockchainConfig.isTotalAmountOverflowTx(-1), "Transaction with id -1 should be a currency sell tx");

chain.setTotalAmountOverflowTxs(null);

assertFalse(blockchainConfig.isTotalAmountOverflowTx(1000), "Transaction with id 1000 should not be a currency " +
"sell tx after chain sell tx cleanup");
}

@Test
void testCreateBlockchainConfig() {
BlockchainConfig blockchainConfig = new BlockchainConfig(chain, new PropertiesHolder());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.apollocurrency.aplwallet.apl.core.transaction.messages.ColoredCoinsOrderPlacementAttachment;
import com.apollocurrency.aplwallet.apl.util.annotation.FeeMarker;
import com.apollocurrency.aplwallet.apl.util.annotation.TransactionFee;
import lombok.SneakyThrows;
import org.json.simple.JSONObject;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -34,6 +35,7 @@
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class CCOrderPlacementTransactionTypeTest {
Expand Down Expand Up @@ -136,6 +138,17 @@ void doStateIndependentValidation_assetIdIsZero() {
"{\"priceATM\":10,\"quantityATU\":20,\"asset\":\"0\",\"version.TestCCOrderPlacement\":1}", ex.getMessage());
}

@SneakyThrows
@Test
void doStateIndependentValidation_txIsInTheOverflowValidationSkipList_OK() {
mockAttachment(1, 20, 10);
doReturn(heightConfig).when(blockchainConfig).getCurrentConfig();
doReturn(10L).when(heightConfig).getMaxBalanceATM();
when(tx.getId()).thenReturn(1000L);
when(blockchainConfig.isTotalAmountOverflowTx(1000L)).thenReturn(true);

type.doStateIndependentValidation(tx);
}
@Test
void doStateIndependentValidation_orderTotalOverflow() {
mockAttachment( 20, Long.MAX_VALUE / 19);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class MSExchangeTransactionTypeTest {
Expand Down Expand Up @@ -102,6 +103,18 @@ void doStateIndependentValidationZeroUnits() {
"\"currency\":\"1\",\"units\":0}", ex.getMessage());
}

@Test
void doStateIndepedentValidation_CurrencySellTxIsChosenByConfigToSkipStrictOverflowValidation_OK() throws AplException.ValidationException {
doReturn(new TestMSExchangeAttachment(1L, 10L, Long.MAX_VALUE)).when(tx).getAttachment();
when(tx.getId()).thenReturn(1000L);
when(blockchainConfig.isTotalAmountOverflowTx(1000L)).thenReturn(true);

type.doStateIndependentValidation(tx);

verify(blockchainConfig).isTotalAmountOverflowTx(1000L);
verifyNoMoreInteractions(blockchainConfig);
}

@Test
void doStateIndependentValidationOrderTotalOverflow() {
doReturn(new TestMSExchangeAttachment(1L, 10L, Long.MAX_VALUE)).when(tx).getAttachment();
Expand All @@ -112,7 +125,8 @@ void doStateIndependentValidationOrderTotalOverflow() {

assertEquals("Result of multiplying x=10, y=9223372036854775807 exceeds the allowed range " +
"[-9223372036854775808;9223372036854775807], transaction='null', type='null', sender='0'", ex.getMessage());
verifyNoInteractions(blockchainConfig);
verify(blockchainConfig).isTotalAmountOverflowTx(0);
verifyNoMoreInteractions(blockchainConfig);
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion apl-crypto/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.apollocurrency</groupId>
<artifactId>apollo-blockchain</artifactId>
<version>1.47.27</version>
<version>1.47.28</version>
</parent>

<artifactId>apl-crypto</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion apl-exec/packaging/pkg-apollo-blockchain.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "apollo-blockchain",
"description": "Apollo blockchain backend",
"version": "1.47.27",
"version": "1.47.28",
"dependencies": [
{
"name": "OpenJDK",
Expand Down
2 changes: 1 addition & 1 deletion apl-exec/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.apollocurrency</groupId>
<artifactId>apollo-blockchain</artifactId>
<version>1.47.27</version>
<version>1.47.28</version>
</parent>

<artifactId>apl-exec</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion apl-updater/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.apollocurrency</groupId>
<artifactId>apollo-blockchain</artifactId>
<version>1.47.27</version>
<version>1.47.28</version>
</parent>

<artifactId>apl-updater</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion apl-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.apollocurrency</groupId>
<artifactId>apollo-blockchain</artifactId>
<version>1.47.27</version>
<version>1.47.28</version>
</parent>

<artifactId>apl-utils</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

public final class Constants {

public static final Version VERSION = new Version("1.47.27");
public static final Version VERSION = new Version("1.47.28");

public static final String APPLICATION = "Apollo";
public static final String APPLICATION_DIR_NAME = "apl-blockchain";
Expand Down
Loading

0 comments on commit 036ff65

Please sign in to comment.