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

bnsd: allow for a zero fee for preregistation record msg #1151

Merged
merged 1 commit into from
Jan 30, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## HEAD

- `bnsd`: set fee to zero for `preregistration.RegisterMsg`
- `bnsd`: add `msgfee.UpdateConfigurationMsg` support
- `bnsd`: a data migration for rewriting blockchain ID to CAIP specified format
- a new `weave.Fraction` type was added to represent fractional values. It
Expand Down
1 change: 1 addition & 0 deletions cmd/bnsd/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func Chain(authFn x.Authenticator, minFee coin.Coin) app.Decorators {
cash.NewDynamicFeeDecorator(authFn, ctrl),
msgfee.NewAntispamFeeDecorator(minFee),
msgfee.NewFeeDecorator(),
preregistration.NewZeroFeeDecorator(),
account.NewAccountMsgFeeDecorator(),
// txfee decorator must be before batch to count the main
// transaction once, not for every message present in the
Expand Down
60 changes: 60 additions & 0 deletions cmd/bnsd/x/preregistration/decorator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package preregistration

import (
weave "github.com/iov-one/weave"
"github.com/iov-one/weave/coin"
"github.com/iov-one/weave/errors"
)

// NewZeroFeeDecorator returns a decorator that lowers the fee for a record
// preregistration message.
func NewZeroFeeDecorator() *ZeroFeeDecorator {
return &ZeroFeeDecorator{}
}

// ZeroFeeDecorator zero fee for a transaction that contains a single message
// of registering a preregistration record. Preregistration records can be
// inserted only by an admin, so even the antispam fee is not necessary.
type ZeroFeeDecorator struct{}

var _ weave.Decorator = (*ZeroFeeDecorator)(nil)

func (*ZeroFeeDecorator) Check(ctx weave.Context, store weave.KVStore, tx weave.Tx, next weave.Checker) (*weave.CheckResult, error) {
res, err := next.Check(ctx, store, tx)
if err != nil {
return res, err
}
if res.RequiredFee.IsZero() {
return res, err
}

msg, err := tx.GetMsg()
if err != nil {
return nil, errors.Wrap(err, "cannot unpack transaction message")
}
if _, ok := msg.(*RegisterMsg); ok {
// Zero the fee.
res.RequiredFee = coin.Coin{}
}
return res, nil
}

func (*ZeroFeeDecorator) Deliver(ctx weave.Context, store weave.KVStore, tx weave.Tx, next weave.Deliverer) (*weave.DeliverResult, error) {
res, err := next.Deliver(ctx, store, tx)
if err != nil {
return res, err
}
if res.RequiredFee.IsZero() {
return res, err
}

msg, err := tx.GetMsg()
if err != nil {
return nil, errors.Wrap(err, "cannot unpack transaction message")
}
if _, ok := msg.(*RegisterMsg); ok {
// Zero the fee.
res.RequiredFee = coin.Coin{}
}
return res, nil
}