Setting proxy forging reward share to 0% removes proxy forging relationship.

Included unit test to cover change.
Modified test blockchain config "test-chain-v2.json" to add maxProxyRelationships.

Added comments to some proxy-related methods in AccountRepository class.
This commit is contained in:
catbref
2019-06-12 10:17:50 +01:00
parent 46dc91e5a0
commit 9af18aad34
5 changed files with 140 additions and 6 deletions

View File

@@ -99,6 +99,7 @@ public interface AccountRepository {
public void save(ProxyForgerData proxyForgerData) throws DataException;
/** Delete proxy forging relationship from repository using passed forger's public key and recipient's address. */
public void delete(byte[] forgerPublickey, String recipient) throws DataException;
// Forging accounts used by BlockGenerator
@@ -107,6 +108,7 @@ public interface AccountRepository {
public void save(ForgingAccountData forgingAccountData) throws DataException;
/** Delete forging account info, used by BlockGenerator, from repository using passed private key. */
public int delete(byte[] forgingAccountSeed) throws DataException;
}

View File

@@ -97,13 +97,19 @@ public class ProxyForgingTransaction extends Transaction {
if (!Crypto.isValidAddress(recipient.getAddress()))
return ValidationResult.INVALID_ADDRESS;
// If proxy public key aleady exists in repository, then it must be for the same forger-recipient combo
// If proxy public key already exists in repository, then it must be for the same forger-recipient combo
ProxyForgerData proxyForgerData = this.repository.getAccountRepository().getProxyForgeData(this.proxyForgingTransactionData.getProxyPublicKey());
if (proxyForgerData != null) {
if (!proxyForgerData.getRecipient().equals(recipient.getAddress()) || !Arrays.equals(proxyForgerData.getForgerPublicKey(), creator.getPublicKey()))
return ValidationResult.INVALID_PUBLIC_KEY;
} else {
// This is a new relationship - check that the generator hasn't reach maximum number of relationships
// This is a new relationship
// No point starting a new relationship with 0% share (i.e. delete relationship)
if (this.proxyForgingTransactionData.getShare().compareTo(BigDecimal.ZERO) == 0)
return ValidationResult.INVALID_FORGE_SHARE;
// Check that the generator hasn't reach maximum number of relationships
int relationshipCount = this.repository.getAccountRepository().countProxyAccounts(creator.getPublicKey());
if (relationshipCount >= BlockChain.getInstance().getMaxProxyRelationships())
return ValidationResult.MAXIMUM_PROXY_RELATIONSHIPS;
@@ -134,9 +140,14 @@ public class ProxyForgingTransaction extends Transaction {
// Save this transaction, with previous share info
this.repository.getTransactionRepository().save(proxyForgingTransactionData);
// Save proxy forging info
proxyForgerData = new ProxyForgerData(forger.getPublicKey(), proxyForgingTransactionData.getRecipient(), proxyForgingTransactionData.getProxyPublicKey(), proxyForgingTransactionData.getShare());
this.repository.getAccountRepository().save(proxyForgerData);
// 0% share is actually a request to delete existing relationship
if (proxyForgingTransactionData.getShare().compareTo(BigDecimal.ZERO) == 0) {
this.repository.getAccountRepository().delete(forger.getPublicKey(), proxyForgingTransactionData.getRecipient());
} else {
// Save proxy forging info
proxyForgerData = new ProxyForgerData(forger.getPublicKey(), proxyForgingTransactionData.getRecipient(), proxyForgingTransactionData.getProxyPublicKey(), proxyForgingTransactionData.getShare());
this.repository.getAccountRepository().save(proxyForgerData);
}
}
@Override