Skip to content

Commit

Permalink
#216 Link msg bandwidth cost doesn't take into account links count
Browse files Browse the repository at this point in the history
  • Loading branch information
arturalbov committed Jan 29, 2019
1 parent 4890ecb commit b3e5416
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const (
CodeCidNotFound sdk.CodeType = 3
CodeNotEnoughBandwidth sdk.CodeType = 4
CodeDuplicatedLink sdk.CodeType = 5
CodeZeroLinks sdk.CodeType = 6

// Code space
CodespaceCbd sdk.CodespaceType = "cyberd"
Expand All @@ -30,6 +31,8 @@ func codeToDefaultMsg(code sdk.CodeType) string {
return "not enough bandwidth to make transaction"
case CodeDuplicatedLink:
return "duplicated link"
case CodeZeroLinks:
return "no links found"
default:
return fmt.Sprintf("unknown error: code %d", code)
}
Expand All @@ -54,6 +57,10 @@ func ErrDuplicatedLink() sdk.Error {
return newError(CodespaceCbd, CodeDuplicatedLink)
}

func ErrZeroLinks() sdk.Error {
return newError(CodespaceCbd, CodeZeroLinks)
}

func newError(codespace sdk.CodespaceType, code sdk.CodeType) sdk.Error {
msg := codeToDefaultMsg(code)
return sdk.NewError(codespace, code, msg)
Expand Down
3 changes: 2 additions & 1 deletion x/bandwidth/cost.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
func MsgBandwidthCosts(msg sdk.Msg) int64 {
switch msg.(type) {
case link.Msg:
return LinkMsgCost
linkMsg := msg.(link.Msg)
return int64(len(linkMsg.Links)) * LinkMsgCost
default:
return NonLinkMsgCost
}
Expand Down
4 changes: 4 additions & 0 deletions x/link/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func (msg Msg) ValidateBasic() sdk.Error {
return sdk.ErrInvalidAddress(msg.Address.String())
}

if len(msg.Links) == 0 {
return cbd.ErrZeroLinks()
}

var filter = make(CidsFilter)

for _, link := range msg.Links {
Expand Down

0 comments on commit b3e5416

Please sign in to comment.