Skip to content

Commit

Permalink
review feedback: add and use constants, better wording for some docum…
Browse files Browse the repository at this point in the history
…entation, remove redundant ValidateBasicChecks

payformessage: use constants and explanation of panic

use namespace and share constants from ll-core

app: added comments to constant copy and pasted from the sdk

review feedback: switch to using constant for namespaceID size

review feedback: change name of GetCommitSignBytes to GetCommitmentSignBytes

review feedback: use the max square size from lazyledger-core instead of 64

fix doc typo

Co-authored-by: John Adler <[email protected]>

review feedback: docs update for the public key method

switch to using constants in the docs too

Update x/lazyledgerapp/types/payformessage.go

Co-authored-by: Ismail Khoffi <[email protected]>

switch to updated PR for cosmos-sdk change and update deps
  • Loading branch information
evan-forbes committed Feb 21, 2021
1 parent 9afafdb commit 04cbae1
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 95 deletions.
33 changes: 17 additions & 16 deletions app/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ import (
core "github.com/lazyledger/lazyledger-core/proto/tendermint/types"
)

// This file should contain all of the althered ABCI methods
const (
// runTxModeDeliver determines if the tx being ran should only be checked,
// or if it should actually modify the state.
// copy and pasted from the sdk, as it is not exported
// https://github.com/lazyledger/cosmos-sdk/blob/3addd7f65d1c35f76716d67641ee629b01f5b9c7/baseapp/baseapp.go#L28
runTxModeDeliver = 3
)

// This file should contain all of the altered ABCI methods

// PreprocessTxs fullfills the lazyledger-core version of the ACBI interface, by
// performing basic validation for the incoming txs, and by cleanly separating
Expand All @@ -30,13 +38,14 @@ func (app *App) PreprocessTxs(txs abci.RequestPreprocessTxs) abci.ResponsePrepro
continue
}

// don't do anything if the transaction doesn't contain a PayForMessage sdk.Msg
// don't process the tx if the transaction doesn't contain a
// PayForMessage sdk.Msg
if !hasWirePayForMessage(tx) {
processedTxs = append(processedTxs, rawTx)
continue
}

// only support transactions that contain a single sdk.Msg for now
// only support transactions that contain a single sdk.Msg
if len(tx.GetMsgs()) != 1 {
continue
}
Expand All @@ -49,7 +58,7 @@ func (app *App) PreprocessTxs(txs abci.RequestPreprocessTxs) abci.ResponsePrepro
continue
}

// process and validate the message
// process the message
coreMsg, signedTx, err := app.processMsg(msg)
if err != nil {
continue
Expand All @@ -58,19 +67,17 @@ func (app *App) PreprocessTxs(txs abci.RequestPreprocessTxs) abci.ResponsePrepro
// execute the tx in runTxModeDeliver mode (3)
// execution includes all validation checks burning fees
// currently, no fees are burned
_, _, err = app.BaseApp.TxRunner()(3, rawTx)
_, _, err = app.BaseApp.TxRunner()(runTxModeDeliver, rawTx)
if err != nil {

continue
}

// increment the share counter by the number of shares taken by the message
sharesTaken := uint64(len(coreMsg.Data) / 256)
sharesTaken := uint64(len(coreMsg.Data) / types.ShareSize)
shareCounter += sharesTaken

// if there are too many shares stop processing and return the transactions
// this is related to issues 67 and 77 of lazyledger-core
if shareCounter > squareSize {
if shareCounter > squareSize*squareSize {
break
}

Expand All @@ -85,7 +92,7 @@ func (app *App) PreprocessTxs(txs abci.RequestPreprocessTxs) abci.ResponsePrepro
processedTxs = append(processedTxs, rawProcessedTx)
}

// sort messages lexographically
// sort messages lexigraphically
sort.Slice(shareMsgs, func(i, j int) bool {
return bytes.Compare(shareMsgs[i].NamespaceId, shareMsgs[j].NamespaceId) < 0
})
Expand Down Expand Up @@ -132,12 +139,6 @@ func (app *App) processMsg(msg sdk.Msg) (core.Message, *types.TxSignedTransactio
fmt.Errorf("No share commit for correct square size. Current square size: %d", squareSize)
}

// run basic validation on the msg
err := wireMsg.ValidateBasic()
if err != nil {
return core.Message{}, nil, err
}

// add the message to the list of core message to be returned to ll-core
coreMsg := core.Message{
NamespaceId: wireMsg.GetMessageNameSpaceId(),
Expand Down
2 changes: 1 addition & 1 deletion app/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ func generateWirePayForMessage(t *testing.T, k uint64, key *secp256k1.PrivKey) *
},
}

rawTxPFM, err := msg.GetCommitSignBytes(k)
rawTxPFM, err := msg.GetCommitmentSignBytes(k)
if err != nil {
t.Error(err)
}
Expand Down
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func New(
BaseApp: bApp,
appName: appName,
// todo(evan): don't hardcode square size
squareSize: 64,
squareSize: lazyledgerapptypes.SquareSize,
cdc: cdc,
appCodec: appCodec,
txConfig: txConfig,
Expand Down
15 changes: 4 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,31 @@ go 1.15

require (
github.com/cosmos/cosmos-sdk v0.40.0-rc5
github.com/gobuffalo/packr/v2 v2.8.1 // indirect
github.com/gogo/protobuf v1.3.2
github.com/golang/protobuf v1.4.3
github.com/golang/snappy v0.0.3-0.20201103224600-674baa8c7fc3 // indirect
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/karrick/godirwalk v1.16.1 // indirect
github.com/lazyledger/lazyledger-core v0.0.0-20210122184344-b83e6766973c
github.com/lazyledger/nmt v0.1.0
github.com/magefile/mage v1.11.0 // indirect
github.com/pelletier/go-toml v1.8.0
github.com/regen-network/cosmos-proto v0.3.1
github.com/rogpeppe/go-internal v1.7.0 // indirect
github.com/rs/zerolog v1.20.0
github.com/sirupsen/logrus v1.7.1 // indirect
github.com/spf13/cast v1.3.1
github.com/spf13/cobra v1.1.3
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.6.1
github.com/tendermint/tm-db v0.6.3
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 // indirect
golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a // indirect
golang.org/x/sys v0.0.0-20210216224549-f992740a1bac // indirect
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf // indirect
golang.org/x/tools v0.1.0 // indirect
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43 // indirect
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
google.golang.org/genproto v0.0.0-20210207032614-bba0dbe2a9ea
google.golang.org/grpc v1.33.2

)

replace (
github.com/cosmos/cosmos-sdk v0.40.0-rc5 => github.com/lazyledger/cosmos-sdk v0.40.0-rc5.0.20210217005603-b260792f5546
github.com/cosmos/cosmos-sdk v0.40.0-rc5 => github.com/lazyledger/cosmos-sdk v0.40.0-rc5.0.20210221170254-8943f1496a14
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.2-alpha.regen.4
golang.org/x/sys => golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // updating this dep will mess up ci and proto generation
)
Loading

0 comments on commit 04cbae1

Please sign in to comment.