forked from Qortal/qortal
OnlineAccountsV3: slightly rework Block.mint() so it doesn't need to filter so many online accounts
Slight optimization to BlockMinter by adding OnlineAccountsManager.hasOnlineAccounts():boolean instead of returning actual data, only to call isEmpty()!
This commit is contained in:
parent
712c4463f7
commit
ae92a6eed4
@ -346,18 +346,22 @@ public class Block {
|
|||||||
int version = parentBlock.getNextBlockVersion();
|
int version = parentBlock.getNextBlockVersion();
|
||||||
byte[] reference = parentBlockData.getSignature();
|
byte[] reference = parentBlockData.getSignature();
|
||||||
|
|
||||||
// Fetch our list of online accounts
|
// Qortal: minter is always a reward-share, so find actual minter and get their effective minting level
|
||||||
List<OnlineAccountData> onlineAccounts = OnlineAccountsManager.getInstance().getOnlineAccounts();
|
int minterLevel = Account.getRewardShareEffectiveMintingLevel(repository, minter.getPublicKey());
|
||||||
if (onlineAccounts.isEmpty()) {
|
if (minterLevel == 0) {
|
||||||
LOGGER.error("No online accounts - not even our own?");
|
LOGGER.error("Minter effective level returned zero?");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find newest online accounts timestamp
|
long timestamp = calcTimestamp(parentBlockData, minter.getPublicKey(), minterLevel);
|
||||||
long onlineAccountsTimestamp = 0;
|
|
||||||
for (OnlineAccountData onlineAccountData : onlineAccounts) {
|
long onlineAccountsTimestamp = OnlineAccountsManager.toOnlineAccountTimestamp(timestamp);
|
||||||
if (onlineAccountData.getTimestamp() > onlineAccountsTimestamp)
|
|
||||||
onlineAccountsTimestamp = onlineAccountData.getTimestamp();
|
// Fetch our list of online accounts
|
||||||
|
List<OnlineAccountData> onlineAccounts = OnlineAccountsManager.getInstance().getOnlineAccounts(onlineAccountsTimestamp);
|
||||||
|
if (onlineAccounts.isEmpty()) {
|
||||||
|
LOGGER.error("No online accounts - not even our own?");
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load sorted list of reward share public keys into memory, so that the indexes can be obtained.
|
// Load sorted list of reward share public keys into memory, so that the indexes can be obtained.
|
||||||
@ -368,10 +372,6 @@ public class Block {
|
|||||||
// Map using index into sorted list of reward-shares as key
|
// Map using index into sorted list of reward-shares as key
|
||||||
Map<Integer, OnlineAccountData> indexedOnlineAccounts = new HashMap<>();
|
Map<Integer, OnlineAccountData> indexedOnlineAccounts = new HashMap<>();
|
||||||
for (OnlineAccountData onlineAccountData : onlineAccounts) {
|
for (OnlineAccountData onlineAccountData : onlineAccounts) {
|
||||||
// Disregard online accounts with different timestamps
|
|
||||||
if (onlineAccountData.getTimestamp() != onlineAccountsTimestamp)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
Integer accountIndex = getRewardShareIndex(onlineAccountData.getPublicKey(), allRewardSharePublicKeys);
|
Integer accountIndex = getRewardShareIndex(onlineAccountData.getPublicKey(), allRewardSharePublicKeys);
|
||||||
if (accountIndex == null)
|
if (accountIndex == null)
|
||||||
// Online account (reward-share) with current timestamp but reward-share cancelled
|
// Online account (reward-share) with current timestamp but reward-share cancelled
|
||||||
@ -399,15 +399,6 @@ public class Block {
|
|||||||
byte[] minterSignature = minter.sign(BlockTransformer.getBytesForMinterSignature(parentBlockData,
|
byte[] minterSignature = minter.sign(BlockTransformer.getBytesForMinterSignature(parentBlockData,
|
||||||
minter.getPublicKey(), encodedOnlineAccounts));
|
minter.getPublicKey(), encodedOnlineAccounts));
|
||||||
|
|
||||||
// Qortal: minter is always a reward-share, so find actual minter and get their effective minting level
|
|
||||||
int minterLevel = Account.getRewardShareEffectiveMintingLevel(repository, minter.getPublicKey());
|
|
||||||
if (minterLevel == 0) {
|
|
||||||
LOGGER.error("Minter effective level returned zero?");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
long timestamp = calcTimestamp(parentBlockData, minter.getPublicKey(), minterLevel);
|
|
||||||
|
|
||||||
int transactionCount = 0;
|
int transactionCount = 0;
|
||||||
byte[] transactionsSignature = null;
|
byte[] transactionsSignature = null;
|
||||||
int height = parentBlockData.getHeight() + 1;
|
int height = parentBlockData.getHeight() + 1;
|
||||||
|
@ -114,8 +114,8 @@ public class BlockMinter extends Thread {
|
|||||||
if (minLatestBlockTimestamp == null)
|
if (minLatestBlockTimestamp == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// No online accounts? (e.g. during startup)
|
// No online accounts for current timestamp? (e.g. during startup)
|
||||||
if (OnlineAccountsManager.getInstance().getOnlineAccounts().isEmpty())
|
if (!OnlineAccountsManager.getInstance().hasOnlineAccounts())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
List<MintingAccountData> mintingAccountsData = repository.getAccountRepository().getMintingAccounts();
|
List<MintingAccountData> mintingAccountsData = repository.getAccountRepository().getMintingAccounts();
|
||||||
|
@ -420,6 +420,20 @@ public class OnlineAccountsManager {
|
|||||||
LOGGER.debug("Broadcasted {} online account{} with timestamp {}", ourOnlineAccounts.size(), (ourOnlineAccounts.size() != 1 ? "s" : ""), onlineAccountsTimestamp);
|
LOGGER.debug("Broadcasted {} online account{} with timestamp {}", ourOnlineAccounts.size(), (ourOnlineAccounts.size() != 1 ? "s" : ""), onlineAccountsTimestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether online accounts manager has any online accounts with timestamp recent enough to be considered currently online.
|
||||||
|
*/
|
||||||
|
// BlockMinter: only calls this to check whether returned list is empty or not, to determine whether minting is even possible or not
|
||||||
|
public boolean hasOnlineAccounts() {
|
||||||
|
final Long now = NTP.getTime();
|
||||||
|
if (now == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
final long onlineTimestamp = toOnlineAccountTimestamp(now);
|
||||||
|
|
||||||
|
return this.currentOnlineAccounts.containsKey(onlineTimestamp);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns list of online accounts matching given timestamp.
|
* Returns list of online accounts matching given timestamp.
|
||||||
*/
|
*/
|
||||||
@ -433,7 +447,6 @@ public class OnlineAccountsManager {
|
|||||||
* Returns list of online accounts with timestamp recent enough to be considered currently online.
|
* Returns list of online accounts with timestamp recent enough to be considered currently online.
|
||||||
*/
|
*/
|
||||||
// API: calls this to return list of online accounts - probably expects ALL timestamps - but going to get 'current' from now on
|
// API: calls this to return list of online accounts - probably expects ALL timestamps - but going to get 'current' from now on
|
||||||
// BlockMinter: only calls this to check whether returned list is empty or not, to determine whether minting is even possible or not
|
|
||||||
public List<OnlineAccountData> getOnlineAccounts() {
|
public List<OnlineAccountData> getOnlineAccounts() {
|
||||||
final Long now = NTP.getTime();
|
final Long now = NTP.getTime();
|
||||||
if (now == null)
|
if (now == null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user