Skip to content
2 changes: 2 additions & 0 deletions chain33.fork.toml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ ForkStorageLocalDB=0
Enable=0
ForkTicketId=1062000
ForkTicketVrf=1770000
# 拒绝同一笔 tclose 交易内重复的 ticketId(重复会等价于同一张票被多次付款)
ForkTicketCloseDup=0
ForkMinerExecerCheck=0

[fork.sub.token]
Expand Down
2 changes: 2 additions & 0 deletions chain33.para.toml
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ Enable=0
Enable=0
ForkTicketId =0
ForkTicketVrf =0
# 拒绝同一笔 tclose 交易内重复的 ticketId(重复会等价于同一张票被多次付款)
ForkTicketCloseDup=0
ForkMinerExecerCheck=0

[fork.sub.retrieve]
Expand Down
2 changes: 2 additions & 0 deletions chain33.para.toml.readme
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ Enable=0
Enable=0
ForkTicketId =0
ForkTicketVrf =0
# 拒绝同一笔 tclose 交易内重复的 ticketId(重复会等价于同一张票被多次付款)
ForkTicketCloseDup=0
ForkMinerExecerCheck=0

[fork.sub.retrieve]
Expand Down

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions plugin/dapp/evm/cmd/ci2/chain33.proxyminer.toml
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,8 @@ ForkStorageLocalDB=0
Enable=0
ForkTicketId=1062000
ForkTicketVrf=1770000
# 拒绝同一笔 tclose 交易内重复的 ticketId(重复会等价于同一张票被多次付款)
ForkTicketCloseDup=0
ForkMinerExecerCheck=0

[fork.sub.token]
Expand Down
1 change: 1 addition & 0 deletions plugin/dapp/ticket/executor/testdata/chain33.cfg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ Enable=0
Enable=0
ForkTicketId = 1600000
ForkTicketVrf = 2070000
ForkTicketCloseDup = 0
ForkMinerExecerCheck = 0

[fork.sub.token]
Expand Down
801 changes: 801 additions & 0 deletions plugin/dapp/ticket/executor/ticketclose_dup_test.go

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions plugin/dapp/ticket/executor/ticketdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,22 @@ func (action *Action) TicketClose(tclose *ty.TicketClose) (*types.Receipt, error
chain33Cfg := action.api.GetConfig()
tickets := make([]*DB, len(tclose.TicketId))
cfg := ty.GetTicketMinerParam(chain33Cfg, action.height)
//分叉后拒绝重复的 ticketId。本方法先在这个循环里校验并构造 tickets, 全部校验完才进入付款
//循环, 中途不写库, 于是同一个 id 出现 N 次会被当成 N 张票各付一次, 而库里只记一次关闭,
//重复支取了该返还地址的押金池(见 ty.ForkTicketCloseDup)
checkDup := chain33Cfg.IsDappFork(action.height, ty.TicketX, ty.ForkTicketCloseDup)
var seenIDs map[string]struct{}
if checkDup {
seenIDs = make(map[string]struct{}, len(tclose.TicketId))
}
for i := 0; i < len(tclose.TicketId); i++ {
if checkDup {
if _, ok := seenIDs[tclose.TicketId[i]]; ok {
tlog.Error("TicketClose repeated ticketId", "id", tclose.TicketId[i], "tx", common.ToHex(action.txhash))
return nil, ty.ErrDupTicketID
}
seenIDs[tclose.TicketId[i]] = struct{}{}
}
ticket, err := readTicket(action.db, tclose.TicketId[i])
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions plugin/dapp/ticket/rpc/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ Enable=0
Enable=0
ForkTicketId =0
ForkTicketVrf =0
ForkTicketCloseDup =0
ForkMinerExecerCheck=0

[fork.sub.retrieve]
Expand Down
2 changes: 2 additions & 0 deletions plugin/dapp/ticket/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ var (
ErrTime = errors.New("ErrTime")
// ErrTicketClosed err type
ErrTicketClosed = errors.New("ErrTicketClosed")
// ErrDupTicketID 同一笔交易内重复关闭同一个 ticket
ErrDupTicketID = errors.New("ErrDupTicketID")
// ErrEmptyMinerTx err type
ErrEmptyMinerTx = errors.New("ErrEmptyMinerTx")
// ErrMinerNotPermit err type
Expand Down
5 changes: 5 additions & 0 deletions plugin/dapp/ticket/types/ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ var ErrOpenTicketPubHash = errors.New("ErrOpenTicketPubHash")
// TicketX dapp name
var TicketX = "ticket"

// ForkTicketCloseDup 修复 TicketClose 对重复 ticketId 重复付款的分叉。
// 开启后同一笔交易内重复出现的 ticketId 会被拒绝(见 executor.TicketClose)。
const ForkTicketCloseDup = "ForkTicketCloseDup"

func init() {
types.AllowUserExec = append(types.AllowUserExec, []byte(TicketX))
types.RegFork(TicketX, InitFork)
Expand All @@ -84,6 +88,7 @@ func InitFork(cfg *types.Chain33Config) {
cfg.RegisterDappFork(TicketX, "Enable", 0)
cfg.RegisterDappFork(TicketX, "ForkTicketId", 0)
cfg.RegisterDappFork(TicketX, "ForkTicketVrf", 0)
cfg.RegisterDappFork(TicketX, ForkTicketCloseDup, 0)
cfg.RegisterDappFork(TicketX, ForkMinerExecerCheck, 0)
}

Expand Down
Loading