Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R4R] Add max lock time in time lock plugin #641

Merged
merged 4 commits into from
Aug 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Changelog
## Develop

BUG FIXES
* [\#641](https://github.com/binance-chain/node/pull/641) [Dex] Add max lock time in time lock plugin
13 changes: 11 additions & 2 deletions plugins/tokens/timelock/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (
const (
MsgRoute = "timelock"

MaxDescriptionLength = 128
MinLockTime = 60 * time.Second
MaxDescriptionLength = 128
MinLockTime = 60 * time.Second
MaxLockTime int64 = 253402300800 //seconds of 10000-01-01, which is required by amino
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go format

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's right

)

var _ sdk.Msg = TimeLockMsg{}
Expand Down Expand Up @@ -54,6 +55,10 @@ func (msg TimeLockMsg) ValidateBasic() sdk.Error {
return ErrInvalidLockTime(DefaultCodespace, fmt.Sprintf("lock time(%d) should be larger than 0", msg.LockTime))
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need hard fork

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, we do not, for there is no such txs included in block

if msg.LockTime >= MaxLockTime {
return ErrInvalidLockTime(DefaultCodespace, fmt.Sprintf("lock time(%d) should be less than %d", msg.LockTime, MaxLockTime))
}

if !msg.Amount.IsValid() {
return sdk.ErrInvalidCoins(msg.Amount.String())
}
Expand Down Expand Up @@ -118,6 +123,10 @@ func (msg TimeRelockMsg) ValidateBasic() sdk.Error {
return ErrInvalidLockTime(DefaultCodespace, fmt.Sprintf("lock time(%d) should not be less than 0", msg.LockTime))
}

if msg.LockTime >= MaxLockTime {
return ErrInvalidLockTime(DefaultCodespace, fmt.Sprintf("lock time(%d) should be less than %d", msg.LockTime, MaxLockTime))
}

if !msg.Amount.IsValid() {
return sdk.ErrInvalidCoins(msg.Amount.String())
}
Expand Down
23 changes: 23 additions & 0 deletions plugins/tokens/timelock/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ func TestTimeLockMsg(t *testing.T) {
pass: true,
errorCode: sdk.CodeType(0),
},
{
from: addrs[0],
description: strings.Repeat("d", 120),
amount: sdk.Coins{
sdk.NewCoin("ANB", 2000e8),
sdk.NewCoin("BNB", 2000e8),
},
lockTime: MaxLockTime,
pass: false,
errorCode: CodeInvalidLockTime,
},
}

for i, tc := range tests {
Expand Down Expand Up @@ -181,6 +192,18 @@ func TestTimeRelockMsg(t *testing.T) {
pass: true,
errorCode: sdk.CodeType(0),
},
{
from: addrs[0],
id: 1,
description: "",
amount: sdk.Coins{
sdk.NewCoin("ANB", 2000e8),
sdk.NewCoin("BNB", 2000e8),
},
lockTime: MaxLockTime,
pass: false,
errorCode: CodeInvalidLockTime,
},
}

for i, tc := range tests {
Expand Down