Skip to content

Commit 6a323f6

Browse files
author
mollkeith
committed
feat(memo): record votes before endTime
1 parent 9f9eca0 commit 6a323f6

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

dpos/state/state.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,7 +1856,7 @@ func (s *State) processTransaction(tx interfaces.Transaction, blockTime uint32,
18561856
s.processDeposit(tx, height)
18571857
}
18581858
s.processCancelVotes(tx, height)
1859-
s.processCancelMemoVotes(tx, height)
1859+
s.processCancelMemoVotes(tx, height, blockTime)
18601860
}
18611861

18621862
func GetOwnerKeyCodeHash(ownerKey []byte) (ownKeyProgramHash *common.Uint160, err error) {
@@ -2274,6 +2274,11 @@ func (s *State) processVotes(tx interfaces.Transaction, blockTime uint32, height
22742274
log.Warn("[memo vote] voteAmount != tx.Outputs()[0].Value")
22752275
continue
22762276
}
2277+
// check endTime with blockTime
2278+
if uint64(blockTime) > s.InitateVotings[userVoting.ID].EndTime {
2279+
log.Warn("[memo vote] blockTime > endTime")
2280+
continue
2281+
}
22772282
op := common2.NewOutPoint(tx.Hash(), 0)
22782283
s.History.Append(height, func() {
22792284
if _, ok := s.UserVotings[userVoting.ID]; !ok {
@@ -2599,12 +2604,12 @@ func (s *State) addProducerAssert(output *common2.Output, height uint32) bool {
25992604
}
26002605

26012606
// processCancelVotes takes a transaction output with vote payload.
2602-
func (s *State) processCancelMemoVotes(tx interfaces.Transaction, height uint32) {
2607+
func (s *State) processCancelMemoVotes(tx interfaces.Transaction, height uint32, blockTime uint32) {
26032608
for _, input := range tx.Inputs() {
26042609
referKey := input.ReferKey()
26052610
_, ok := s.MemoVotes[referKey]
26062611
if ok {
2607-
s.processMemoVoteCancel(referKey, height)
2612+
s.processMemoVoteCancel(referKey, height, uint64(blockTime))
26082613
}
26092614
}
26102615
}
@@ -2677,8 +2682,12 @@ func (s *State) processVoteOutput(output *common2.Output, height uint32) {
26772682
}
26782683

26792684
// processVoteCancel takes a previous vote output and decrease producers votes.
2680-
func (s *State) processMemoVoteCancel(referKey string, height uint32) {
2685+
func (s *State) processMemoVoteCancel(referKey string, height uint32, blockTime uint64) {
26812686
for k, v := range s.UserVotings {
2687+
iv := s.InitateVotings[k]
2688+
if blockTime > iv.EndTime {
2689+
continue
2690+
}
26822691
key := k
26832692
if vote, ok := v[referKey]; ok {
26842693
s.History.Append(height, func() {

0 commit comments

Comments
 (0)