diff --git a/src/main/java/com/github/ontio/explorer/statistics/mapper/BadNodeMapper.java b/src/main/java/com/github/ontio/explorer/statistics/mapper/BadNodeMapper.java new file mode 100644 index 0000000..46aab3d --- /dev/null +++ b/src/main/java/com/github/ontio/explorer/statistics/mapper/BadNodeMapper.java @@ -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 { + +} \ No newline at end of file diff --git a/src/main/java/com/github/ontio/explorer/statistics/model/BadNode.java b/src/main/java/com/github/ontio/explorer/statistics/model/BadNode.java new file mode 100644 index 0000000..f98dc9c --- /dev/null +++ b/src/main/java/com/github/ontio/explorer/statistics/model/BadNode.java @@ -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; +} \ No newline at end of file diff --git a/src/main/java/com/github/ontio/explorer/statistics/service/ConsensusNodeService.java b/src/main/java/com/github/ontio/explorer/statistics/service/ConsensusNodeService.java index 1a5837e..9752f00 100644 --- a/src/main/java/com/github/ontio/explorer/statistics/service/ConsensusNodeService.java +++ b/src/main/java/com/github/ontio/explorer/statistics/service/ConsensusNodeService.java @@ -79,6 +79,8 @@ public class ConsensusNodeService { private BlockMapper blockMapper; + private BadNodeMapper badNodeMapper; + @Autowired public ConsensusNodeService(ParamsConfig paramsConfig, ObjectMapper objectMapper, @@ -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; @@ -112,6 +115,7 @@ public ConsensusNodeService(ParamsConfig paramsConfig, this.txEventLogMapper = txEventLogMapper; this.nodeCycleMapper = nodeCycleMapper; this.blockMapper = blockMapper; + this.badNodeMapper = badNodeMapper; } public void updateBlockCountToNextRound() { @@ -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); + } } } }