Skip to content

Commit

Permalink
rename after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-forbes committed May 10, 2022
1 parent ec36e5d commit 35fcff5
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 54 deletions.
15 changes: 3 additions & 12 deletions app/prepare_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))))

Expand Down Expand Up @@ -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
}

Expand All @@ -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
}
Expand Down
40 changes: 20 additions & 20 deletions app/split_shares.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/test/prepare_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
}
Expand Down
10 changes: 5 additions & 5 deletions app/test/process_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions docs/architecture/ADR-001-ABCI++.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
...
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion x/payment/types/payfordata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion x/payment/types/payfordata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
6 changes: 3 additions & 3 deletions x/payment/types/wirepayfordata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

0 comments on commit 35fcff5

Please sign in to comment.