Skip to content

Commit

Permalink
Record bad node each round
Browse files Browse the repository at this point in the history
  • Loading branch information
leej1012 committed Aug 9, 2024
1 parent 58cdd3e commit 3f2a0d7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.github.ontio.explorer.statistics.mapper;

import com.github.ontio.explorer.statistics.model.BadNode;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;


@Repository
public interface BadNodeMapper extends Mapper<BadNode> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.github.ontio.explorer.statistics.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "tbl_bad_node")
public class BadNode {
@Id
@GeneratedValue(generator = "JDBC")
private Integer id;

@Column(name = "public_key")
private String publicKey;

private Integer cycle;
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public class ConsensusNodeService {

private BlockMapper blockMapper;

private BadNodeMapper badNodeMapper;

@Autowired
public ConsensusNodeService(ParamsConfig paramsConfig,
ObjectMapper objectMapper,
Expand All @@ -95,7 +97,8 @@ public ConsensusNodeService(ParamsConfig paramsConfig,
InspireCalculationParamsMapper inspireCalculationParamsMapper,
TxEventLogMapper txEventLogMapper,
NodeCycleMapper nodeCycleMapper,
BlockMapper blockMapper) {
BlockMapper blockMapper,
BadNodeMapper badNodeMapper) {
this.paramsConfig = paramsConfig;
this.ontSdkService = ontSdkService;
this.objectMapper = objectMapper;
Expand All @@ -112,6 +115,7 @@ public ConsensusNodeService(ParamsConfig paramsConfig,
this.txEventLogMapper = txEventLogMapper;
this.nodeCycleMapper = nodeCycleMapper;
this.blockMapper = blockMapper;
this.badNodeMapper = badNodeMapper;
}

public void updateBlockCountToNextRound() {
Expand Down Expand Up @@ -1076,10 +1080,18 @@ public void updateNodeState() {
Example example = new Example(NodeInfoOffChain.class);
example.createCriteria().andEqualTo("publicKey", publicKey);
NodeInfoOffChain entity = nodeInfoOffChainMapper.selectOneByExample(example);
Integer badActorBefore = entity.getBadActor();
entity.setFeeSharingRatio(stable);
entity.setBadActor(badActor);
entity.setRisky(risky);
nodeInfoOffChainMapper.updateByPrimaryKeySelective(entity);

if (badActor == 1 && badActorBefore == 0) {
BadNode badNode = new BadNode();
badNode.setPublicKey(publicKey);
badNode.setCycle(currentCycle);
badNodeMapper.insertSelective(badNode);
}
}
}
}

0 comments on commit 3f2a0d7

Please sign in to comment.