Skip to content

Commit

Permalink
Changes need to be reverted prior to the PR from crowetic repo being …
Browse files Browse the repository at this point in the history
…merged. All of these changes aside from those in the 'network' folder, will be re-applied with crowetic's PR.

Revert "Various changes"

This reverts commit adbba0f.
  • Loading branch information
crowetic committed Dec 4, 2024
1 parent 8d68301 commit 9b20192
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 180 deletions.
20 changes: 1 addition & 19 deletions src/main/java/org/qortal/account/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,27 +348,9 @@ public int getEffectiveMintingLevel() throws DataException {
return accountData.getLevel();
}

/**
* Returns reward-share minting address, or unknown if reward-share does not exist.
*
* @param repository
* @param rewardSharePublicKey
* @return address or unknown
* @throws DataException
*/
public static String getRewardShareMintingAddress(Repository repository, byte[] rewardSharePublicKey) throws DataException {
// Find actual minter address
RewardShareData rewardShareData = repository.getAccountRepository().getRewardShare(rewardSharePublicKey);

if (rewardShareData == null)
return "Unknown";

return rewardShareData.getMinter();
}

/**
* Returns 'effective' minting level, or zero if reward-share does not exist.
*
*
* @param repository
* @param rewardSharePublicKey
* @return 0+
Expand Down
33 changes: 0 additions & 33 deletions src/main/java/org/qortal/api/model/ApiOnlineAccount.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
package org.qortal.api.model;

import org.qortal.account.Account;
import org.qortal.repository.DataException;
import org.qortal.repository.RepositoryManager;
import org.qortal.repository.Repository;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

// All properties to be converted to JSON via JAXB
@XmlAccessorType(XmlAccessType.FIELD)
Expand Down Expand Up @@ -53,31 +47,4 @@ public String getRecipientAddress() {
return this.recipientAddress;
}

public int getMinterLevelFromPublicKey() {
try (final Repository repository = RepositoryManager.getRepository()) {
return Account.getRewardShareEffectiveMintingLevel(repository, this.rewardSharePublicKey);
} catch (DataException e) {
return 0;
}
}

public boolean getIsMember() {
try (final Repository repository = RepositoryManager.getRepository()) {
return repository.getGroupRepository().memberExists(694, getMinterAddress());
} catch (DataException e) {
return false;
}
}

// JAXB special

@XmlElement(name = "minterLevel")
protected int getMinterLevel() {
return getMinterLevelFromPublicKey();
}

@XmlElement(name = "isMinterMember")
protected boolean getMinterMember() {
return getIsMember();
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/qortal/api/model/BlockMintingInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
public class BlockMintingInfo {

public byte[] minterPublicKey;
public String minterAddress;
public int minterLevel;
public int onlineAccountsCount;
public BigDecimal maxDistance;
Expand All @@ -20,4 +19,5 @@ public class BlockMintingInfo {

public BlockMintingInfo() {
}

}
3 changes: 1 addition & 2 deletions src/main/java/org/qortal/api/resource/BlocksResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,6 @@ public BlockMintingInfo getBlockMintingInfoByHeight(@PathParam("height") int hei
}
}

String minterAddress = Account.getRewardShareMintingAddress(repository, blockData.getMinterPublicKey());
int minterLevel = Account.getRewardShareEffectiveMintingLevel(repository, blockData.getMinterPublicKey());
if (minterLevel == 0)
// This may be unavailable when requesting a trimmed block
Expand All @@ -555,7 +554,6 @@ public BlockMintingInfo getBlockMintingInfoByHeight(@PathParam("height") int hei

BlockMintingInfo blockMintingInfo = new BlockMintingInfo();
blockMintingInfo.minterPublicKey = blockData.getMinterPublicKey();
blockMintingInfo.minterAddress = minterAddress;
blockMintingInfo.minterLevel = minterLevel;
blockMintingInfo.onlineAccountsCount = blockData.getOnlineAccountsCount();
blockMintingInfo.maxDistance = new BigDecimal(block.MAX_DISTANCE);
Expand Down Expand Up @@ -889,4 +887,5 @@ public List<BlockSummaryData> getBlockSummaries(
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
}
}

}
51 changes: 12 additions & 39 deletions src/main/java/org/qortal/block/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public static class ExpandedAccount {

private final Account recipientAccount;
private final AccountData recipientAccountData;

final BlockChain blockChain = BlockChain.getInstance();

ExpandedAccount(Repository repository, RewardShareData rewardShareData) throws DataException {
Expand Down Expand Up @@ -414,21 +414,6 @@ else if (isOnlineAccountsBlock(height)) {
});
}

// After feature trigger, remove any online accounts that are not minter group member
if (height >= BlockChain.getInstance().getGroupMemberCheckHeight()) {
onlineAccounts.removeIf(a -> {
try {
int groupId = BlockChain.getInstance().getMintingGroupId();
String address = Account.getRewardShareMintingAddress(repository, a.getPublicKey());
boolean isMinterGroupMember = repository.getGroupRepository().memberExists(groupId, address);
return !isMinterGroupMember;
} catch (DataException e) {
// Something went wrong, so remove the account
return true;
}
});
}

if (onlineAccounts.isEmpty()) {
LOGGER.debug("No online accounts - not even our own?");
return null;
Expand Down Expand Up @@ -736,19 +721,19 @@ public List<ExpandedAccount> getExpandedAccounts() throws DataException {
List<ExpandedAccount> expandedAccounts = new ArrayList<>();

for (RewardShareData rewardShare : this.cachedOnlineRewardShares) {
int groupId = BlockChain.getInstance().getMintingGroupId();
String address = rewardShare.getMinter();
boolean isMinterGroupMember = repository.getGroupRepository().memberExists(groupId, address);

if (this.getBlockData().getHeight() < BlockChain.getInstance().getFixBatchRewardHeight())
expandedAccounts.add(new ExpandedAccount(repository, rewardShare));

if (this.getBlockData().getHeight() >= BlockChain.getInstance().getFixBatchRewardHeight() && isMinterGroupMember)
if (this.getBlockData().getHeight() < BlockChain.getInstance().getFixBatchRewardHeight()) {
expandedAccounts.add(new ExpandedAccount(repository, rewardShare));
}
if (this.getBlockData().getHeight() >= BlockChain.getInstance().getFixBatchRewardHeight()) {
boolean isMinterGroupMember = repository.getGroupRepository().memberExists(BlockChain.getInstance().getMintingGroupId(), rewardShare.getMinter());
if (isMinterGroupMember) {
expandedAccounts.add(new ExpandedAccount(repository, rewardShare));
}
}
}


this.cachedExpandedAccounts = expandedAccounts;
LOGGER.trace(() -> String.format("Online reward-shares after expanded accounts %s", this.cachedOnlineRewardShares));

return this.cachedExpandedAccounts;
}
Expand Down Expand Up @@ -1158,17 +1143,8 @@ public ValidationResult areOnlineAccountsValid() throws DataException {
if (this.getBlockData().getHeight() >= BlockChain.getInstance().getOnlineAccountMinterLevelValidationHeight()) {
List<ExpandedAccount> expandedAccounts = this.getExpandedAccounts();
for (ExpandedAccount account : expandedAccounts) {
int groupId = BlockChain.getInstance().getMintingGroupId();
String address = account.getMintingAccount().getAddress();
boolean isMinterGroupMember = repository.getGroupRepository().memberExists(groupId, address);

if (account.getMintingAccount().getEffectiveMintingLevel() == 0)
return ValidationResult.ONLINE_ACCOUNTS_INVALID;

if (this.getBlockData().getHeight() >= BlockChain.getInstance().getFixBatchRewardHeight()) {
if (!isMinterGroupMember)
return ValidationResult.ONLINE_ACCOUNTS_INVALID;
}
}
}

Expand Down Expand Up @@ -1297,7 +1273,6 @@ public ValidationResult isValid() throws DataException {

// Online Accounts
ValidationResult onlineAccountsResult = this.areOnlineAccountsValid();
LOGGER.trace("Accounts valid = {}", onlineAccountsResult);
if (onlineAccountsResult != ValidationResult.OK)
return onlineAccountsResult;

Expand Down Expand Up @@ -1386,7 +1361,7 @@ private ValidationResult areTransactionsValid() throws DataException {
// Check transaction can even be processed
validationResult = transaction.isProcessable();
if (validationResult != Transaction.ValidationResult.OK) {
LOGGER.debug(String.format("Error during transaction validation, tx %s: %s", Base58.encode(transactionData.getSignature()), validationResult.name()));
LOGGER.info(String.format("Error during transaction validation, tx %s: %s", Base58.encode(transactionData.getSignature()), validationResult.name()));
return ValidationResult.TRANSACTION_INVALID;
}

Expand Down Expand Up @@ -1587,7 +1562,6 @@ public void process() throws DataException {
this.blockData.setHeight(blockchainHeight + 1);

LOGGER.trace(() -> String.format("Processing block %d", this.blockData.getHeight()));
LOGGER.trace(() -> String.format("Online Reward Shares in process %s", this.cachedOnlineRewardShares));

if (this.blockData.getHeight() > 1) {

Expand Down Expand Up @@ -2306,6 +2280,7 @@ protected List<BlockRewardCandidate> determineBlockRewardCandidates(boolean isPr
// Select the correct set of share bins based on block height
List<AccountLevelShareBin> accountLevelShareBinsForBlock = (this.blockData.getHeight() >= BlockChain.getInstance().getSharesByLevelV2Height()) ?
BlockChain.getInstance().getAccountLevelShareBinsV2() : BlockChain.getInstance().getAccountLevelShareBinsV1();

// Determine reward candidates based on account level
// This needs a deep copy, so the shares can be modified when tiers aren't activated yet
List<AccountLevelShareBin> accountLevelShareBins = new ArrayList<>();
Expand Down Expand Up @@ -2595,11 +2570,9 @@ private void logDebugInfo() {
return;

int minterLevel = Account.getRewardShareEffectiveMintingLevel(this.repository, this.getMinter().getPublicKey());
String minterAddress = Account.getRewardShareMintingAddress(this.repository, this.getMinter().getPublicKey());

LOGGER.debug(String.format("======= BLOCK %d (%.8s) =======", this.getBlockData().getHeight(), Base58.encode(this.getSignature())));
LOGGER.debug(String.format("Timestamp: %d", this.getBlockData().getTimestamp()));
LOGGER.debug(String.format("Minter address: %s", minterAddress));
LOGGER.debug(String.format("Minter level: %d", minterLevel));
LOGGER.debug(String.format("Online accounts: %d", this.getBlockData().getOnlineAccountsCount()));
LOGGER.debug(String.format("AT count: %d", this.getBlockData().getATCount()));
Expand Down
29 changes: 3 additions & 26 deletions src/main/java/org/qortal/data/block/BlockData.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package org.qortal.data.block;

import com.google.common.primitives.Bytes;
import org.qortal.account.Account;
import org.qortal.block.BlockChain;
import org.qortal.repository.DataException;
import org.qortal.repository.Repository;
import org.qortal.repository.RepositoryManager;
import org.qortal.crypto.Crypto;
import org.qortal.settings.Settings;
import org.qortal.utils.NTP;

Expand Down Expand Up @@ -227,39 +224,19 @@ public int getOnlineAccountsSignaturesCount() {
}
return 0;
}

public boolean isTrimmed() {
long onlineAccountSignaturesTrimmedTimestamp = NTP.getTime() - BlockChain.getInstance().getOnlineAccountSignaturesMaxLifetime();
long currentTrimmableTimestamp = NTP.getTime() - Settings.getInstance().getAtStatesMaxLifetime();
long blockTimestamp = this.getTimestamp();
return blockTimestamp < onlineAccountSignaturesTrimmedTimestamp && blockTimestamp < currentTrimmableTimestamp;
}

public String getMinterAddressFromPublicKey() {
try (final Repository repository = RepositoryManager.getRepository()) {
return Account.getRewardShareMintingAddress(repository, this.minterPublicKey);
} catch (DataException e) {
return "Unknown";
}
}

public int getMinterLevelFromPublicKey() {
try (final Repository repository = RepositoryManager.getRepository()) {
return Account.getRewardShareEffectiveMintingLevel(repository, this.minterPublicKey);
} catch (DataException e) {
return 0;
}
}

// JAXB special

@XmlElement(name = "minterAddress")
protected String getMinterAddress() {
return getMinterAddressFromPublicKey();
return Crypto.toAddress(this.minterPublicKey);
}

@XmlElement(name = "minterLevel")
protected int getMinterLevel() {
return getMinterLevelFromPublicKey();
}
}
26 changes: 13 additions & 13 deletions src/main/java/org/qortal/network/Handshake.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Handshake onMessage(Peer peer, Message message) {

String versionString = helloMessage.getVersionString();

Matcher matcher = Peer.VERSION_PATTERN.matcher(versionString);
Matcher matcher = peer.VERSION_PATTERN.matcher(versionString);
if (!matcher.lookingAt()) {
LOGGER.debug(() -> String.format("Peer %s sent invalid HELLO version string '%s'", peer, versionString));
return null;
Expand All @@ -71,15 +71,15 @@ public Handshake onMessage(Peer peer, Message message) {

// Ensure the peer is running at least the version specified in MIN_PEER_VERSION
if (!peer.isAtLeastVersion(MIN_PEER_VERSION)) {
LOGGER.debug("Ignoring peer {} because it is on an old version ({})", peer, versionString);
LOGGER.debug(String.format("Ignoring peer %s because it is on an old version (%s)", peer, versionString));
return null;
}

if (!Settings.getInstance().getAllowConnectionsWithOlderPeerVersions()) {
// Ensure the peer is running at least the minimum version allowed for connections
final String minPeerVersion = Settings.getInstance().getMinPeerVersion();
if (!peer.isAtLeastVersion(minPeerVersion)) {
LOGGER.debug("Ignoring peer {} because it is on an old version ({})", peer, versionString);
LOGGER.debug(String.format("Ignoring peer %s because it is on an old version (%s)", peer, versionString));
return null;
}
}
Expand All @@ -106,7 +106,7 @@ public Handshake onMessage(Peer peer, Message message) {
byte[] peersPublicKey = challengeMessage.getPublicKey();
byte[] peersChallenge = challengeMessage.getChallenge();

// If public key matches our public key, then we've connected to self
// If public key matches our public key then we've connected to self
byte[] ourPublicKey = Network.getInstance().getOurPublicKey();
if (Arrays.equals(ourPublicKey, peersPublicKey)) {
// If outgoing connection then record destination as self so we don't try again
Expand All @@ -121,11 +121,11 @@ public Handshake onMessage(Peer peer, Message message) {
peer.disconnect("failed to send CHALLENGE to self");

/*
* We return the CHALLENGE here to prevent us from closing the connection.
* Closing the connection currently preempts the remote end from reading any pending messages,
* We return CHALLENGE here to prevent us from closing connection. Closing
* connection currently preempts remote end from reading any pending messages,
* specifically the CHALLENGE message we just sent above. When our 'remote'
* outbound counterpart reads our message, they will close both connections.
* Failing that, our connection will time out or a future handshake error will
* Failing that, our connection will timeout or a future handshake error will
* occur.
*/
return CHALLENGE;
Expand All @@ -135,7 +135,7 @@ public Handshake onMessage(Peer peer, Message message) {
// Are we already connected to this peer?
Peer existingPeer = Network.getInstance().getHandshakedPeerWithPublicKey(peersPublicKey);
if (existingPeer != null) {
LOGGER.debug(() -> String.format("We already have a connection with peer %s - discarding", peer));
LOGGER.info(() -> String.format("We already have a connection with peer %s - discarding", peer));
// Handshake failure - caller will deal with disconnect
return null;
}
Expand All @@ -148,7 +148,7 @@ public Handshake onMessage(Peer peer, Message message) {

@Override
public void action(Peer peer) {
// Send a challenge
// Send challenge
byte[] publicKey = Network.getInstance().getOurPublicKey();
byte[] challenge = peer.getOurChallenge();

Expand Down Expand Up @@ -254,17 +254,16 @@ public void action(Peer peer) {

private static final Logger LOGGER = LogManager.getLogger(Handshake.class);

/** The Maximum allowed difference between peer's reported timestamp and when they connected, in milliseconds. */
/** Maximum allowed difference between peer's reported timestamp and when they connected, in milliseconds. */
private static final long MAX_TIMESTAMP_DELTA = 30 * 1000L; // ms

private static final long PEER_VERSION_131 = 0x0100030001L;

/** Minimum peer version that we are allowed to communicate with */
private static final String MIN_PEER_VERSION = "4.6.5";
private static final String MIN_PEER_VERSION = "4.1.1";

private static final int POW_BUFFER_SIZE_PRE_131 = 8 * 1024 * 1024; // bytes
private static final int POW_DIFFICULTY_PRE_131 = 8; // leading zero bits

// Can always be made harder in the future...
private static final int POW_BUFFER_SIZE_POST_131 = 2 * 1024 * 1024; // bytes
private static final int POW_DIFFICULTY_POST_131 = 2; // leading zero bits
Expand All @@ -276,11 +275,12 @@ public void action(Peer peer) {

public final MessageType expectedMessageType;

Handshake(MessageType expectedMessageType) {
private Handshake(MessageType expectedMessageType) {
this.expectedMessageType = expectedMessageType;
}

public abstract Handshake onMessage(Peer peer, Message message);

public abstract void action(Peer peer);

}
Loading

0 comments on commit 9b20192

Please sign in to comment.