use of io.nuls.consensus.entity.YellowPunishData in project nuls by nuls-io.
the class YellowPunishTxService method onCommit.
@Override
public void onCommit(YellowPunishTransaction tx) throws NulsException {
YellowPunishData data = tx.getTxData();
for (Address address : data.getAddressList()) {
PunishLogPo po = new PunishLogPo();
po.setAddress(address.getBase58());
po.setHeight(data.getHeight());
po.setId(StringUtils.getNewUUID());
po.setTime(tx.getTime());
po.setType(PunishType.YELLOW.getCode());
punishLogDataService.save(po);
}
}
use of io.nuls.consensus.entity.YellowPunishData in project nuls by nuls-io.
the class ConsensusMeetingRunner method yellowPunishTx.
private void yellowPunishTx(Block bestBlock, List<Transaction> txList, PocMeetingMember self) throws NulsException, IOException {
BlockRoundData lastBlockRoundData = new BlockRoundData();
try {
lastBlockRoundData.parse(bestBlock.getHeader().getExtend());
} catch (NulsException e) {
Log.error(e);
}
// continuous blocks in the same round
boolean ok = (self.getRoundIndex() == lastBlockRoundData.getRoundIndex()) && (self.getIndexOfRound() == (1 + lastBlockRoundData.getPackingIndexOfRound()));
// continuous blocks between two rounds
ok = ok || (self.getRoundIndex() == (lastBlockRoundData.getRoundIndex() + 1) && self.getIndexOfRound() == 1 && lastBlockRoundData.getPackingIndexOfRound() == lastBlockRoundData.getConsensusMemberCount());
// two rounds
ok = ok || (self.getRoundIndex() - 1) > lastBlockRoundData.getRoundIndex();
if (ok) {
return;
}
List<Address> addressList = new ArrayList<>();
PocMeetingRound round = consensusManager.getCurrentRound();
long roundIndex = lastBlockRoundData.getRoundIndex();
int packingIndex = 0;
if (lastBlockRoundData.getPackingIndexOfRound() == lastBlockRoundData.getConsensusMemberCount()) {
packingIndex = 1;
} else {
packingIndex = lastBlockRoundData.getPackingIndexOfRound() + 1;
}
while (true) {
PocMeetingRound tempRound;
if (roundIndex == self.getRoundIndex()) {
tempRound = round;
} else if (roundIndex == (self.getRoundIndex() - 1)) {
tempRound = round.getPreviousRound();
} else {
break;
}
if (tempRound.getIndex() > round.getIndex()) {
break;
}
if (tempRound.getIndex() == round.getIndex() && packingIndex >= self.getIndexOfRound()) {
break;
}
if (packingIndex >= tempRound.getMemberCount()) {
roundIndex++;
packingIndex = 1;
continue;
}
PocMeetingMember member;
try {
member = tempRound.getMember(packingIndex);
if (null == member) {
break;
}
} catch (Exception e) {
break;
}
packingIndex++;
addressList.add(Address.fromHashs(member.getAgentAddress()));
}
if (addressList.isEmpty()) {
return;
}
YellowPunishTransaction punishTx = new YellowPunishTransaction();
YellowPunishData data = new YellowPunishData();
data.setAddressList(addressList);
data.setHeight(bestBlock.getHeader().getHeight() + 1);
punishTx.setTxData(data);
punishTx.setTime(TimeService.currentTimeMillis());
punishTx.setFee(Na.ZERO);
punishTx.setHash(NulsDigestData.calcDigestData(punishTx));
punishTx.setScriptSig(accountService.createP2PKHScriptSigFromDigest(punishTx.getHash(), consensusManager.getConsensusStatusInfo().getAccount(), NulsContext.CACHED_PASSWORD_OF_WALLET).serialize());
txList.add(punishTx);
}
use of io.nuls.consensus.entity.YellowPunishData in project nuls by nuls-io.
the class YellowPunishTxService method onRollback.
@Override
public void onRollback(YellowPunishTransaction tx) throws NulsException {
YellowPunishData data = tx.getTxData();
this.punishLogDataService.deleteByHeight(data.getHeight());
}
Aggregations