Skip to content

Commit 77a454c

Browse files
committed
Adding PoC+ support.
1 parent 74149e1 commit 77a454c

File tree

7 files changed

+61
-11
lines changed

7 files changed

+61
-11
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ def dbusername = "root"
3636
dependencies {
3737
implementation 'org.apache.poi:poi-ooxml:4.1.0'
3838
implementation 'io.reactivex.rxjava2:rxjava:2.2.10'
39-
// implementation 'com.github.burst-apps-team:burstkit4j:0.15.1'
40-
implementation 'com.github.jjos2372:burstkit4j:35fbdae491'
39+
implementation 'com.github.burst-apps-team:burstkit4j:8846b302ea'
40+
//implementation 'com.github.jjos2372:burstkit4j:35fbdae491'
4141
implementation 'org.nanohttpd:nanohttpd:2.3.1'
4242
implementation "org.flywaydb:flyway-core:6.5.0"
4343
implementation "com.h2database:h2:1.4.199"

dist/pool.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ maxDeadline = 1000000000
4747
# short lived network forks.
4848
processLag = 10
4949

50+
# The block to activate PoC+
51+
pocPlusBlock = 271000
52+
5053
# Recipient of pool fees
5154
feeRecipient=BURST-W5YR-ZZQC-KUBJ-G78KB
5255
# Percentage of each block reward taken by pool (1 = 100%)

src/main/java/burst/pool/miners/Miner.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public class Miner implements Payable {
1717

1818
private final BurstAddress address;
1919
private final MinerStore store;
20+
private int commitmentHeight;
21+
private AtomicReference<BurstValue> commitment = new AtomicReference<>();
2022

2123
public Miner(MinerMaths minerMaths, PropertyService propertyService, BurstAddress address, MinerStore store) {
2224
this.minerMaths = minerMaths;
@@ -156,7 +158,23 @@ public String getName() {
156158
public void setName(String name) {
157159
store.setName(name);
158160
}
159-
161+
162+
public void setCommitment(BurstValue commitment, int height) {
163+
this.commitment.set(commitment);
164+
this.commitmentHeight = height;
165+
}
166+
167+
public BurstValue getCommitment() {
168+
BurstValue value = commitment.get();
169+
if(value == null)
170+
value = BurstValue.fromBurst(0);
171+
return value;
172+
}
173+
174+
public int getCommitmentHeight() {
175+
return this.commitmentHeight;
176+
}
177+
160178
public String getUserAgent() {
161179
return store.getUserAgent();
162180
}

src/main/java/burst/pool/miners/MinerTracker.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import burst.kit.entity.BurstID;
66
import burst.kit.entity.BurstValue;
77
import burst.kit.entity.response.Account;
8+
import burst.kit.entity.response.MiningInfo;
89
import burst.kit.service.BurstNodeService;
910
import burst.pool.entity.Payout;
1011
import burst.pool.entity.WonBlock;
@@ -39,12 +40,38 @@ public MinerTracker(BurstNodeService nodeService, PropertyService propertyServic
3940
this.propertyService = propertyService;
4041
}
4142

42-
public void onMinerSubmittedDeadline(StorageService storageService, BurstAddress minerAddress, BigInteger deadline, BigInteger baseTarget, long blockHeight, String userAgent) {
43+
public void onMinerSubmittedDeadline(StorageService storageService, BurstAddress minerAddress, BigInteger deadline, BigInteger baseTarget, MiningInfo miningInfo, String userAgent) {
4344
waitUntilNotProcessingBlock();
4445
Miner miner = getOrCreate(storageService, minerAddress);
46+
47+
int blockHeight = (int) miningInfo.getHeight();
48+
49+
if(miner.getCommitmentHeight() != blockHeight) {
50+
miner.setUserAgent(userAgent);
51+
try {
52+
Account accountResponse = nodeService.getAccount(minerAddress, blockHeight, true).blockingGet();
53+
onMinerAccount(storageService, accountResponse, blockHeight);
54+
}
55+
catch (Exception e) {
56+
miner.setCommitment(null, blockHeight);
57+
onMinerAccountError(e);
58+
}
59+
}
60+
61+
if(blockHeight >= propertyService.getInt(Props.pocPlusBlock)) {
62+
// PoC+ logic
63+
BurstValue commitment = miner.getCommitment();
64+
65+
double commitmentFactor = commitment.doubleValue()/miningInfo.getAverageCommitment();
66+
commitmentFactor = Math.pow(commitmentFactor, 0.4515449935);
67+
commitmentFactor = Math.min(8.0, commitmentFactor);
68+
commitmentFactor = Math.max(0.125, commitmentFactor);
69+
70+
double newDeadline = deadline.longValue()/commitmentFactor;
71+
72+
deadline = BigInteger.valueOf((long)newDeadline);
73+
}
4574
miner.processNewDeadline(new Deadline(deadline, baseTarget, miner.getSharePercent(), blockHeight));
46-
miner.setUserAgent(userAgent);
47-
compositeDisposable.add(nodeService.getAccount(minerAddress).subscribe(accountResponse -> onMinerAccount(storageService, accountResponse), this::onMinerAccountError));
4875
}
4976

5077
private Miner getOrCreate(StorageService storageService, BurstAddress minerAddress) {
@@ -220,12 +247,13 @@ private void onPayoutError(Throwable throwable) {
220247
}
221248

222249

223-
private void onMinerAccount(StorageService storageService, Account accountResponse) {
250+
private void onMinerAccount(StorageService storageService, Account accountResponse, int height) {
224251
waitUntilNotProcessingBlock();
225252
Miner miner = storageService.getMiner(accountResponse.getId());
226253
if (miner == null) return;
227254
if (accountResponse.getName() == null) return;
228255
miner.setName(accountResponse.getName());
256+
miner.setCommitment(accountResponse.getCommitment(), height);
229257
}
230258

231259
private void onMinerAccountError(Throwable throwable) {

src/main/java/burst/pool/pool/Pool.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ private void resetRound(MiningInfo newMiningInfo) {
313313
if(miningInfo.get()!=null) {
314314
long mod = miningInfo.get().getHeight() % (transferBlocks);
315315
if(mod == 0L) {
316-
Account balance = nodeService.getAccount(secondaryAddress).blockingGet();
316+
Account balance = nodeService.getAccount(secondaryAddress, null, null).blockingGet();
317317
if(balance.getBalance().compareTo(BurstValue.fromBurst(propertyService.getFloat(Props.minimumMinimumPayout))) > 0) {
318318
BurstValue amountToSend = balance.getBalance().subtract(getTransactionFee());
319319
byte[] unsignedBytes = nodeService.generateTransaction(primaryAddress, burstCrypto.getPublicKey(passphrase), amountToSend,
@@ -392,7 +392,7 @@ BigInteger checkNewSubmission(Submission submission, String userAgent) throws Su
392392
onNewBestDeadline(miningInfo.get().getHeight(), submission, deadline);
393393
}
394394

395-
minerTracker.onMinerSubmittedDeadline(storageService, submission.getMiner(), deadline, BigInteger.valueOf(miningInfo.get().getBaseTarget()), miningInfo.get().getHeight(), userAgent);
395+
minerTracker.onMinerSubmittedDeadline(storageService, submission.getMiner(), deadline, BigInteger.valueOf(miningInfo.get().getBaseTarget()), miningInfo.get(), userAgent);
396396
return deadline;
397397
} finally {
398398
processDeadlineSemaphore.release();
@@ -466,7 +466,7 @@ public JsonObject getCurrentRoundInfo(Gson gson) {
466466
if (miningInfo != null) {
467467
long baseTarget = miningInfo.getBaseTarget();
468468
baseTarget = (long)(baseTarget * 1.83f);
469-
jsonObject.add("miningInfo", gson.toJsonTree(new MiningInfoResponse(burstCrypto.toHexString(miningInfo.getGenerationSignature()), baseTarget, miningInfo.getHeight())));
469+
jsonObject.add("miningInfo", gson.toJsonTree(new MiningInfoResponse(burstCrypto.toHexString(miningInfo.getGenerationSignature()), baseTarget, miningInfo.getHeight(), miningInfo.getAverageCommitment())));
470470
}
471471
return jsonObject;
472472
}

src/main/java/burst/pool/pool/Server.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ private String handleBurstApiCall(IHTTPSession session, Map<String, String> para
116116
} else if (Objects.equals(params.get("requestType"), "getMiningInfo")) {
117117
MiningInfo miningInfo = pool.getMiningInfo();
118118
if (miningInfo == null) return gson.toJson(JsonNull.INSTANCE);
119-
return gson.toJson(new MiningInfoResponse(burstCrypto.toHexString(miningInfo.getGenerationSignature()), miningInfo.getBaseTarget(), miningInfo.getHeight()));
119+
return gson.toJson(new MiningInfoResponse(burstCrypto.toHexString(miningInfo.getGenerationSignature()), miningInfo.getBaseTarget(), miningInfo.getHeight(), miningInfo.getAverageCommitment()));
120120
} else {
121121
return "404 not found";
122122
}

src/main/java/burst/pool/storage/config/Props.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class Props {
2525
public static final Prop<Integer> nMin = new Prop<>("nMin", 1); // Must be ?
2626
public static final Prop<Long> maxDeadline = new Prop<>("maxDeadline", Long.MAX_VALUE); // Must be > 0
2727
public static final Prop<Integer> processLag = new Prop<>("processLag", 10); // Must be > 0
28+
public static final Prop<Integer> pocPlusBlock = new Prop<>("pocPlusBlock", 271_000);
2829

2930
public static final Prop<BurstAddress> feeRecipient = new Prop<>("feeRecipient", null); // Must be non null
3031
public static final Prop<BurstAddress> donationRecipient = new Prop<>("donationRecipient", null); // Must be non null

0 commit comments

Comments
 (0)