Reflect code review comments

This commit is contained in:
Manfred Karrer 2019-03-14 22:01:38 -05:00
parent 59bed76c0c
commit 3411cde8b7
No known key found for this signature in database
GPG key ID: 401250966A6B2C46
3 changed files with 12 additions and 5 deletions

View file

@ -233,8 +233,10 @@ public class DaoStateMonitoringService implements DaoSetupService, DaoStateListe
}
} else {
// TODO check if in reorg cases it might be a valid case
checkArgument(height > daoStateBlockChain.getLast().getHeight(),
"We got a block the same blockHeight as our previous block in the daoStateBlockchain.");
checkArgument(height == daoStateBlockChain.getLast().getHeight() + 1,
"New block must be 1 block above previous block. height={}, " +
"daoStateBlockChain.getLast().getHeight()={}",
height, daoStateBlockChain.getLast().getHeight());
prevHash = daoStateBlockChain.getLast().getHash();
}
byte[] stateHash = daoStateService.getSerializedDaoState();
@ -256,6 +258,7 @@ public class DaoStateMonitoringService implements DaoSetupService, DaoStateListe
// We delay broadcast to give peers enough time to have received the block.
// Otherwise they would ignore our data if received block is in future to their local blockchain.
//TODO increase to 5-10 sec
int delayInSec = 1 + new Random().nextInt(5);
UserThread.runAfter(() -> daoStateNetworkService.broadcastMyStateHash(myDaoStateHash), delayInSec);
}

View file

@ -85,6 +85,7 @@ public abstract class StateNetworkService<Msg extends NewStateHashMessage,
@Getter
private final Map<NodeAddress, Han> requestStateHashHandlerMap = new HashMap<>();
private final List<Listener<Msg, Req, StH>> listeners = new CopyOnWriteArrayList<>();
private boolean messageListenerAdded;
///////////////////////////////////////////////////////////////////////////////////////////
@ -147,7 +148,10 @@ public abstract class StateNetworkService<Msg extends NewStateHashMessage,
///////////////////////////////////////////////////////////////////////////////////////////
public void addListeners() {
if (!messageListenerAdded) {
networkNode.addMessageListener(this);
messageListenerAdded = true;
}
}
public void sendGetStateHashesResponse(Connection connection, int nonce, List<StH> stateHashes) {

View file

@ -175,9 +175,9 @@ public class DaoStateService implements DaoSetupService {
return daoState.getCycles();
}
public void addCycle(Cycle firstCycle) {
public void addCycle(Cycle cycle) {
assertDaoStateChange();
getCycles().add(firstCycle);
getCycles().add(cycle);
}
@Nullable