Skip to content

Commit

Permalink
Block punishment improvement
Browse files Browse the repository at this point in the history
Signed-off-by: domhauton <domhauton@gmail.com>
  • Loading branch information
domhauton committed Apr 28, 2017
1 parent 3136207 commit 19ddca4
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .idea/modules/membraned.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/modules/membraned_main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules/membraned_test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: "nebula.deb"
apply plugin: 'nebula.rpm'

project.version = '1.0.0-alpha.5'
project.version = '1.0.0-alpha.6'
project.group = 'com.domhauton.membrane'

jar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public Set<EvidenceRequest> processPeerContractUpdate(String peerId, DateTime da
Set<String> expectedBlocks = blockIds.stream()
.filter(myBlockIds::contains)
.collect(Collectors.toSet());
Set<String> blocksToSkip = appraisalLedger.getReportsRecieved(peerId, dateTime, myBlockIds.size());
Set<String> blocksToSkip = appraisalLedger.getReportsReceived(peerId, dateTime, myBlockIds.size());
Set<EvidenceRequest> activeBlockRequests = getActiveBlockEvidenceRequests(dateTime, expectedBlocks, blocksToSkip);

// Aggregate all generated evidence requests.
Expand Down Expand Up @@ -548,7 +548,7 @@ EvidenceResponse processEvidenceRequest(String peer, EvidenceRequest evidenceReq
public void run() {
executorService.scheduleAtFixedRate(this::sendUpdateToAllContractedPeers,
TIME_BEFORE_FIRST_BROADCAST_MINS,
DateTimeConstants.MINUTES_PER_HOUR,
DateTimeConstants.MINUTES_PER_HOUR / 4,
TimeUnit.MINUTES);

executorService.scheduleAtFixedRate(this::distributeShards,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void registerLostBlock(String peerId, DateTime lostDateTime, int expected
getPeerAppraisal(peerId).addLostBlock(lostDateTime, expectedBlocks);
}

public Set<String> getReportsRecieved(String peerId, DateTime dateTime, long expectedBlocks) {
public Set<String> getReportsReceived(String peerId, DateTime dateTime, long expectedBlocks) {
return getPeerAppraisal(peerId).getReportsReceived(dateTime, expectedBlocks);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.apache.logging.log4j.Logger;
import org.joda.time.DateTime;
import org.joda.time.DateTimeConstants;
import org.joda.time.Hours;

import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -215,7 +216,9 @@ synchronized void addLostBlock(DateTime dateTimeLost, int totalExpectedBlocks) {
* @return Chance [0.0,1.0]
*/
double getBlockLosingRate() {
double chanceOfLosingBlocks = totalLifetimeBlocks <= 0 ? 0.0d : (double) lostBlocks / (double) totalLifetimeBlocks;
double punishmentMultiplier = Math.min(DateTimeConstants.HOURS_PER_WEEK * 2, Math.abs(Hours.hoursBetween(firstInteractionTime, DateTime.now()).getHours()));
punishmentMultiplier = Math.max(1.0, punishmentMultiplier);
double chanceOfLosingBlocks = totalLifetimeBlocks <= 0 ? 0.0d : ((double) lostBlocks * punishmentMultiplier) / (double) totalLifetimeBlocks;
// Clamp between 0.0d and 1.0d
return Math.min(chanceOfLosingBlocks, 1.0d);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ void blockSaltedHashTest() throws Exception {
// Receive response
contractManagerImpl2.processEvidenceResponses(PEER_1, baseDateTime, evidenceResponses);

Assertions.assertEquals(Collections.singleton(blockId), appraisalLedgerInner2.getReportsRecieved(PEER_1, baseDateTime, 1));
Assertions.assertEquals(Collections.singleton(blockId), appraisalLedgerInner2.getReportsReceived(PEER_1, baseDateTime, 1));
}

private void setupConnection() {
Expand Down

0 comments on commit 19ddca4

Please sign in to comment.