From 35fcff506b90d9aaa9eb3b361d81b81bc13d8afd Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Tue, 10 May 2022 10:30:46 -0500 Subject: [PATCH] rename after rebase --- app/prepare_proposal.go | 15 +++-------- app/split_shares.go | 40 ++++++++++++++--------------- app/test/prepare_proposal_test.go | 6 ++--- app/test/process_proposal_test.go | 10 ++++---- docs/architecture/ADR-001-ABCI++.md | 12 ++++----- go.mod | 2 +- go.sum | 4 +-- x/payment/types/payfordata.go | 2 +- x/payment/types/payfordata_test.go | 2 +- x/payment/types/wirepayfordata.go | 6 ++--- 10 files changed, 45 insertions(+), 54 deletions(-) diff --git a/app/prepare_proposal.go b/app/prepare_proposal.go index d3aa203ba0..cf1175ac20 100644 --- a/app/prepare_proposal.go +++ b/app/prepare_proposal.go @@ -65,18 +65,9 @@ func (app *App) estimateSquareSize(data *core.Data) uint64 { evdShareEstimate++ // add one to round up } - isrBytes := 0 - for _, isr := range data.IntermediateStateRoots.RawRootsList { - isrBytes += len(isr) + delimLen(uint64(len(isr))) - } - isrShareEstimate := isrBytes / consts.TxShareSize - if isrBytes > 0 { - isrShareEstimate++ // add one to round up - } - msgShareEstimate := estimateMsgShares(app.txConfig, data.Txs) - totalShareEstimate := txShareEstimate + evdShareEstimate + isrShareEstimate + msgShareEstimate + totalShareEstimate := txShareEstimate + evdShareEstimate + msgShareEstimate estimatedSize := types.NextPowerOf2(uint64(math.Sqrt(float64(totalShareEstimate)))) @@ -106,7 +97,7 @@ func estimateMsgShares(txConf client.TxConfig, txs [][]byte) int { } // write the tx to the square if it normal - if !hasWirePayForMessage(authTx) { + if !hasWirePayForData(authTx) { continue } @@ -116,7 +107,7 @@ func estimateMsgShares(txConf client.TxConfig, txs [][]byte) int { } msg := authTx.GetMsgs()[0] - wireMsg, ok := msg.(*types.MsgWirePayForMessage) + wireMsg, ok := msg.(*types.MsgWirePayForData) if !ok { continue } diff --git a/app/split_shares.go b/app/split_shares.go index 55e1c8f702..478b6ea088 100644 --- a/app/split_shares.go +++ b/app/split_shares.go @@ -15,8 +15,8 @@ import ( ) // WriteSquare uses the provided block data to create a flattened data square. -// Any MsgWirePayForMessages are malleated, and their corresponding -// MsgPayForMessage and Message are written atomically. If there are +// Any MsgWirePayForDatas are malleated, and their corresponding +// MsgPayForData and Message are written atomically. If there are // transactions that will node fit in the given square size, then they are // discarded. This is reflected in the returned block data. Note: pointers to // block data are only used to avoid dereferening, not because we need the block @@ -41,7 +41,7 @@ func SplitShares(txConf client.TxConfig, squareSize uint64, data *core.Data) ([] } // write the tx to the square if it normal - if !hasWirePayForMessage(authTx) { + if !hasWirePayForData(authTx) { success, err := sqwr.writeTx(rawTx) if err != nil { continue @@ -60,7 +60,7 @@ func SplitShares(txConf client.TxConfig, squareSize uint64, data *core.Data) ([] } msg := authTx.GetMsgs()[0] - wireMsg, ok := msg.(*types.MsgWirePayForMessage) + wireMsg, ok := msg.(*types.MsgWirePayForData) if !ok { continue } @@ -100,10 +100,10 @@ func SplitShares(txConf client.TxConfig, squareSize uint64, data *core.Data) ([] } } -// squareWriter write a data square using provided block data. It also ensures +// shareSplitter write a data square using provided block data. It also ensures // that message and their corresponding txs get written to the square // atomically. -type squareWriter struct { +type shareSplitter struct { txWriter *coretypes.ContiguousShareWriter msgWriter *coretypes.MessageShareWriter @@ -139,7 +139,7 @@ func newShareSplitter(txConf client.TxConfig, squareSize uint64, data *core.Data // writeTx marshals the tx and lazily writes it to the square. Returns true if // the write was successful, false if there was not enough room in the square. -func (sqwr *squareWriter) writeTx(tx []byte) (ok bool, err error) { +func (sqwr *shareSplitter) writeTx(tx []byte) (ok bool, err error) { delimTx, err := coretypes.Tx(tx).MarshalDelimited() if err != nil { return false, err @@ -153,24 +153,24 @@ func (sqwr *squareWriter) writeTx(tx []byte) (ok bool, err error) { return true, nil } -// writeMalleated malleates a MsgWirePayForMessage into a MsgPayForMessage and -// its corresponding message provided that it has a MsgPayForMessage for the +// writeMalleated malleates a MsgWirePayForData into a MsgPayForData and +// its corresponding message provided that it has a MsgPayForData for the // preselected square size. Returns true if the write was successful, false if // there was not enough room in the square. -func (sqwr *squareWriter) writeMalleatedTx( +func (sqwr *shareSplitter) writeMalleatedTx( parentHash []byte, tx signing.Tx, - wpfm *types.MsgWirePayForMessage, + wpfd *types.MsgWirePayForData, ) (ok bool, malleatedTx coretypes.Tx, msg *core.Message, err error) { // parse wire message and create a single message - coreMsg, unsignedPFM, sig, err := types.ProcessWirePayForMessage(wpfm, sqwr.squareSize) + coreMsg, unsignedPFD, sig, err := types.ProcessWirePayForData(wpfd, sqwr.squareSize) if err != nil { return false, nil, nil, err } - // create the signed PayForMessage using the fees, gas limit, and sequence from + // create the signed PayForData using the fees, gas limit, and sequence from // the original transaction, along with the appropriate signature. - signedTx, err := types.BuildPayForMessageTxFromWireTx(tx, sqwr.txConf.NewTxBuilder(), sig, unsignedPFM) + signedTx, err := types.BuildPayForDataTxFromWireTx(tx, sqwr.txConf.NewTxBuilder(), sig, unsignedPFD) if err != nil { return false, nil, nil, err } @@ -205,7 +205,7 @@ func (sqwr *squareWriter) writeMalleatedTx( return true, wrappedTx, coreMsg, nil } -func (sqwr *squareWriter) hasRoomForBoth(tx, msg []byte) bool { +func (sqwr *shareSplitter) hasRoomForBoth(tx, msg []byte) bool { currentShareCount, availableBytes := sqwr.shareCount() txBytesTaken := delimLen(uint64(len(tx))) + len(tx) @@ -217,7 +217,7 @@ func (sqwr *squareWriter) hasRoomForBoth(tx, msg []byte) bool { return currentShareCount+maxTxSharesTaken+maxMsgSharesTaken <= sqwr.maxShareCount } -func (sqwr *squareWriter) hasRoomForTx(tx []byte) bool { +func (sqwr *shareSplitter) hasRoomForTx(tx []byte) bool { currentShareCount, availableBytes := sqwr.shareCount() bytesTaken := delimLen(uint64(len(tx))) + len(tx) @@ -230,13 +230,13 @@ func (sqwr *squareWriter) hasRoomForTx(tx []byte) bool { return currentShareCount+maxSharesTaken <= sqwr.maxShareCount } -func (sqwr *squareWriter) shareCount() (count, availableTxBytes int) { +func (sqwr *shareSplitter) shareCount() (count, availableTxBytes int) { txsShareCount, availableBytes := sqwr.txWriter.Count() return txsShareCount + len(sqwr.isrShares) + len(sqwr.evdShares) + sqwr.msgWriter.Count(), availableBytes } -func (sqwr *squareWriter) export() [][]byte { +func (sqwr *shareSplitter) export() [][]byte { count, pendingTxBytes := sqwr.shareCount() // increment the count if there are any pending tx bytes if pendingTxBytes > 0 { @@ -278,10 +278,10 @@ func (sqwr *squareWriter) export() [][]byte { return shares } -func hasWirePayForMessage(tx sdk.Tx) bool { +func hasWirePayForData(tx sdk.Tx) bool { for _, msg := range tx.GetMsgs() { msgName := sdk.MsgTypeURL(msg) - if msgName == types.URLMsgWirePayforMessage { + if msgName == types.URLMsgWirePayForData { return true } } diff --git a/app/test/prepare_proposal_test.go b/app/test/prepare_proposal_test.go index d819be91d7..b15c0f8680 100644 --- a/app/test/prepare_proposal_test.go +++ b/app/test/prepare_proposal_test.go @@ -77,7 +77,7 @@ func TestPrepareProposal(t *testing.T) { func generateRawTx(t *testing.T, txConfig client.TxConfig, ns, message []byte, signer *types.KeyringSigner, ks ...uint64) (rawTx []byte) { // create a msg - msg := generateSignedWirePayForMessage(t, ns, message, signer, ks...) + msg := generateSignedWirePayForData(t, ns, message, signer, ks...) builder := signer.NewTxBuilder() @@ -100,8 +100,8 @@ func generateRawTx(t *testing.T, txConfig client.TxConfig, ns, message []byte, s return rawTx } -func generateSignedWirePayForMessage(t *testing.T, ns, message []byte, signer *types.KeyringSigner, ks ...uint64) *types.MsgWirePayForMessage { - msg, err := types.NewWirePayForMessage(ns, message, ks...) +func generateSignedWirePayForData(t *testing.T, ns, message []byte, signer *types.KeyringSigner, ks ...uint64) *types.MsgWirePayForData { + msg, err := types.NewWirePayForData(ns, message, ks...) if err != nil { t.Error(err) } diff --git a/app/test/process_proposal_test.go b/app/test/process_proposal_test.go index 1cf67327c1..0cf13c7245 100644 --- a/app/test/process_proposal_test.go +++ b/app/test/process_proposal_test.go @@ -28,11 +28,11 @@ func TestMessageInclusionCheck(t *testing.T) { encConf := cosmoscmd.MakeEncodingConfig(app.ModuleBasics) - firstValidPFM, msg1 := genRandMsgPayForMessage(t, signer, 8) - secondValidPFM, msg2 := genRandMsgPayForMessage(t, signer, 8) + firstValidPFD, msg1 := genRandMsgPayForData(t, signer, 8) + secondValidPFD, msg2 := genRandMsgPayForData(t, signer, 8) - invalidCommitmentPFM, msg3 := genRandMsgPayForMessage(t, signer, 4) - invalidCommitmentPFM.MessageShareCommitment = tmrand.Bytes(32) + invalidCommitmentPFD, msg3 := genRandMsgPayForData(t, signer, 4) + invalidCommitmentPFD.MessageShareCommitment = tmrand.Bytes(32) // block with all messages included validData := core.Data{ @@ -165,7 +165,7 @@ func TestMessageInclusionCheck(t *testing.T) { } -func genRandMsgPayForMessage(t *testing.T, signer *types.KeyringSigner, squareSize uint64) (*types.MsgPayForMessage, []byte) { +func genRandMsgPayForData(t *testing.T, signer *types.KeyringSigner, squareSize uint64) (*types.MsgPayForData, []byte) { ns := make([]byte, consts.NamespaceSize) _, err := rand.Read(ns) require.NoError(t, err) diff --git a/docs/architecture/ADR-001-ABCI++.md b/docs/architecture/ADR-001-ABCI++.md index 2afdff220c..b4be68bd4b 100644 --- a/docs/architecture/ADR-001-ABCI++.md +++ b/docs/architecture/ADR-001-ABCI++.md @@ -202,13 +202,13 @@ type MessageShareWriter struct { } ``` -These types are combined in a new celestia-app type, `squareWriter`, which is responsible for atomically writing transactions and their corresponding messages to the data square and the returned block data. +These types are combined in a new celestia-app type, `shareSplitter`, which is responsible for atomically writing transactions and their corresponding messages to the data square and the returned block data. ```go -// squareWriter writes a data square using provided block data. It also ensures +// shareSplitter writes a data square using provided block data. It also ensures // that message and their corresponding txs get written to the square // atomically. -type squareWriter struct { +type shareSplitter struct { txWriter *coretypes.ContiguousShareWriter msgWriter *coretypes.MessageShareWriter ... @@ -228,7 +228,7 @@ func SplitShares(txConf client.TxConfig, squareSize uint64, data *core.Data) ([] processedTxs [][]byte messages core.Messages ) - sqwr, err := newSquareWriter(txConf, squareSize, data) + sqwr, err := newShareSplitter(txConf, squareSize, data) if err != nil { return nil, nil, err } @@ -283,7 +283,7 @@ func SplitShares(txConf client.TxConfig, squareSize uint64, data *core.Data) ([] // writeTx marshals the tx and lazily writes it to the square. Returns true if // the write was successful, false if there was not enough room in the square. -func (sqwr *squareWriter) writeTx(tx []byte) (ok bool, err error) { +func (sqwr *shareSplitter) writeTx(tx []byte) (ok bool, err error) { delimTx, err := coretypes.Tx(tx).MarshalDelimited() if err != nil { return false, err @@ -301,7 +301,7 @@ func (sqwr *squareWriter) writeTx(tx []byte) (ok bool, err error) { // its corresponding message provided that it has a MsgPayForData for the // preselected square size. Returns true if the write was successful, false if // there was not enough room in the square. -func (sqwr *squareWriter) writeMalleatedTx( +func (sqwr *shareSplitter) writeMalleatedTx( parentHash []byte, tx signing.Tx, wpfd *types.MsgWirePayForData, diff --git a/go.mod b/go.mod index bcff311881..225567a7b1 100644 --- a/go.mod +++ b/go.mod @@ -36,7 +36,7 @@ require ( github.com/btcsuite/btcd v0.22.0-beta // indirect github.com/celestiaorg/go-leopard v0.1.0 // indirect github.com/celestiaorg/merkletree v0.0.0-20210714075610-a84dc3ddbbe4 // indirect - github.com/celestiaorg/rsmt2d v0.3.1 // indirect + github.com/celestiaorg/rsmt2d v0.4.0 // indirect github.com/cespare/xxhash v1.1.0 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/coinbase/rosetta-sdk-go v0.6.10 // indirect diff --git a/go.sum b/go.sum index 26df828468..a5beb68786 100644 --- a/go.sum +++ b/go.sum @@ -158,8 +158,8 @@ github.com/celestiaorg/merkletree v0.0.0-20210714075610-a84dc3ddbbe4 h1:CJdIpo8n github.com/celestiaorg/merkletree v0.0.0-20210714075610-a84dc3ddbbe4/go.mod h1:fzuHnhzj1pUygGz+1ZkB3uQbEUL4htqCGJ4Qs2LwMZA= github.com/celestiaorg/nmt v0.8.0 h1:wtX7GRouLbmBe+ffnc8+cOg2UbWteM+Y1imZuZ/EeqU= github.com/celestiaorg/nmt v0.8.0/go.mod h1:3bqzTj8xKj0DgQUpOgZzoxvtNkC3MS/hTbQ6dn8SIa0= -github.com/celestiaorg/rsmt2d v0.3.1 h1:qFp6oZXG+QsMO8FqnI34EQ/j+yuJnlddC+nnAkQCq1Y= -github.com/celestiaorg/rsmt2d v0.3.1/go.mod h1:2Frw4GEYUnVu6Mvlo+CUzuC2/8wn+zLwVVtp+muN6vg= +github.com/celestiaorg/rsmt2d v0.4.0 h1:mpICbeXYKE1yNW8VBzgBrcnzuMKzutpROH1g2xI7Ls4= +github.com/celestiaorg/rsmt2d v0.4.0/go.mod h1:EZ+O2KdCq8xI7WFwjATLdhtMdrdClmAs2w7zENDr010= github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= diff --git a/x/payment/types/payfordata.go b/x/payment/types/payfordata.go index 50b7c0718d..04273519fc 100644 --- a/x/payment/types/payfordata.go +++ b/x/payment/types/payfordata.go @@ -228,7 +228,7 @@ func NextPowerOf2(v uint64) uint64 { } // Check if number is power of 2 -func PowerOf2(v uint64) bool { +func powerOf2(v uint64) bool { if v&(v-1) == 0 && v != 0 { return true } else { diff --git a/x/payment/types/payfordata_test.go b/x/payment/types/payfordata_test.go index f8701ca5ba..5c2ce1ac3b 100644 --- a/x/payment/types/payfordata_test.go +++ b/x/payment/types/payfordata_test.go @@ -106,7 +106,7 @@ func TestPowerOf2(t *testing.T) { }, } for _, tt := range tests { - res := PowerOf2(tt.input) + res := powerOf2(tt.input) assert.Equal(t, tt.expected, res) } } diff --git a/x/payment/types/wirepayfordata.go b/x/payment/types/wirepayfordata.go index 88c213b951..a29ee68aeb 100644 --- a/x/payment/types/wirepayfordata.go +++ b/x/payment/types/wirepayfordata.go @@ -106,8 +106,8 @@ func (msg *MsgWirePayForData) ValidateBasic() error { for idx, commit := range msg.MessageShareCommitment { // check that each commit is valid - if !PowerOf2(commit.K) { - return fmt.Errorf("invalid square size, the size must be power of 2: %d", commit.K) + if !powerOf2(commit.K) { + return ErrCommittedSquareSizeNotPowOf2.Wrapf("committed to square size: %d", commit.K) } calculatedCommit, err := CreateCommitment(commit.K, msg.GetMessageNameSpaceId(), msg.Message) @@ -213,5 +213,5 @@ func ProcessWirePayForData(msg *MsgWirePayForData, squareSize uint64) (*tmproto. return nil, nil, nil, err } - return &coreMsg, pfm, shareCommit.Signature, nil + return &coreMsg, pfd, shareCommit.Signature, nil }