Skip to content

Commit

Permalink
change left over pfm to pfd
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-forbes committed Apr 29, 2022
1 parent 07816a7 commit 7978689
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 50 deletions.
4 changes: 2 additions & 2 deletions app/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ func (app *App) PrepareProposal(req abci.RequestPrepareProposal) abci.ResponsePr
}

// parse wire message and create a single message
coreMsg, unsignedPFM, sig, err := types.ProcessWirePayForData(wireMsg, app.SquareSize())
coreMsg, unsignedPFD, sig, err := types.ProcessWirePayForData(wireMsg, app.SquareSize())
if err != nil {
continue
}

// create the signed PayForData using the fees, gas limit, and sequence from
// the original transaction, along with the appropriate signature.
signedTx, err := types.BuildPayForDataTxFromWireTx(authTx, app.txConfig.NewTxBuilder(), sig, unsignedPFM)
signedTx, err := types.BuildPayForDataTxFromWireTx(authTx, app.txConfig.NewTxBuilder(), sig, unsignedPFD)
if err != nil {
app.Logger().Error("failure to create signed PayForData", err)
continue
Expand Down
8 changes: 4 additions & 4 deletions docs/architecture/ADR-001-ABCI++.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (sqwr *squareWriter) writeTx(tx []byte) (ok bool, err error) {
func (sqwr *squareWriter) writeMalleatedTx(
parentHash []byte,
tx signing.Tx,
wpfm *types.MsgWirePayForData,
wpfd *types.MsgWirePayForData,
) (ok bool, malleatedTx coretypes.Tx, msg *core.Message, err error) {
... // process the malleated tx and extract the message.

Expand Down Expand Up @@ -339,18 +339,18 @@ During `ProcessProposal`, we
func (app *App) ProcessProposal(req abci.RequestProcessProposal) abci.ResponseProcessProposal {
// Check for message inclusion:
// - each MsgPayForData included in a block should have a corresponding message also in the block data
// - the commitment in each PFM should match that of its corresponding message
// - the commitment in each PFD should match that of its corresponding message
// - there should be no unpaid for messages

// extract the commitments from any MsgPayForDatas in the block
commitments := make(map[string]struct{})
for _, rawTx := range req.BlockData.Txs {
...
commitments[string(pfm.MessageShareCommitment)] = struct{}{}
commitments[string(pfd.MessageShareCommitment)] = struct{}{}
...
}

// quickly compare the number of PFMs and messages, if they aren't
// quickly compare the number of PFDs and messages, if they aren't
// identical, then we already know this block is invalid
if len(commitments) != len(req.BlockData.Messages.MessagesList) {
... // logging and rejecting
Expand Down
10 changes: 5 additions & 5 deletions x/payment/client/cli/wirepayfordata.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func CmdWirePayForData() *cobra.Command {
return err
}
squareSizes64 := parseSquareSizes(squareSizes)
pfmMsg, err := types.NewWirePayForData(namespace, message, squareSizes64...)
pfdMsg, err := types.NewWirePayForData(namespace, message, squareSizes64...)
if err != nil {
return err
}
Expand Down Expand Up @@ -91,7 +91,7 @@ func CmdWirePayForData() *cobra.Command {
}

// sign the MsgPayForData's ShareCommitments
err = pfmMsg.SignShareCommitments(
err = pfdMsg.SignShareCommitments(
signer,
types.SetGasLimit(gasSetting.Gas),
types.SetFeeAmount(parsedFees),
Expand All @@ -101,10 +101,10 @@ func CmdWirePayForData() *cobra.Command {
}

// run message checks
if err = pfmMsg.ValidateBasic(); err != nil {
if err = pfdMsg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), pfmMsg)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), pfdMsg)
},
}

Expand All @@ -120,4 +120,4 @@ func parseSquareSizes(squareSizes []uint) []uint64 {
squareSizes64[i] = uint64(squareSizes[i])
}
return squareSizes64
}
}
14 changes: 7 additions & 7 deletions x/payment/spec/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ func ProcessWirePayForData(msg *MsgWirePayForData, squareSize uint64) (*tmproto.
}

// wrap the signed transaction data
pfm, err := msg.unsignedPayForData(squareSize)
pfd, err := msg.unsignedPayForData(squareSize)
if err != nil {
return nil, nil, nil, err
}

return &coreMsg, pfm, shareCommit.Signature, nil
return &coreMsg, pfd, shareCommit.Signature, nil
}

// PreprocessTxs fulfills the celestia-core version of the ABCI interface, by
Expand All @@ -64,14 +64,14 @@ func (app *App) PreprocessTxs(txs abci.RequestPreprocessTxs) abci.ResponsePrepro
// boiler plate
...
// parse wire message and create a single message
coreMsg, unsignedPFM, sig, err := types.ProcessWirePayForData(wireMsg, app.SquareSize())
coreMsg, unsignedPFD, sig, err := types.ProcessWirePayForData(wireMsg, app.SquareSize())
if err != nil {
continue
}

// create the signed PayForData using the fees, gas limit, and sequence from
// the original transaction, along with the appropriate signature.
signedTx, err := types.BuildPayForDataTxFromWireTx(authTx, app.txConfig.NewTxBuilder(), sig, unsignedPFM)
signedTx, err := types.BuildPayForDataTxFromWireTx(authTx, app.txConfig.NewTxBuilder(), sig, unsignedPFD)
if err != nil {
app.Logger().Error("failure to create signed PayForData", err)
continue
Expand All @@ -98,7 +98,7 @@ There are no parameters yet, but we might add
There are tools to programmatically create, sign, and broadcast `MsgWirePayForDatas`
```go
// create the raw WirePayForData transaction
wpfmMsg, err := apptypes.NewWirePayForData(block.Header.NamespaceId, message, 16, 32, 64, 128)
wpfdMsg, err := apptypes.NewWirePayForData(block.Header.NamespaceId, message, 16, 32, 64, 128)
if err != nil {
return err
}
Expand All @@ -121,7 +121,7 @@ if err != nil {
// generate the signatures for each `MsgPayForData` using the `KeyringSigner`,
// then set the gas limit for the tx
gasLimOption := types.SetGasLimit(200000)
err = pfmMsg.SignShareCommitments(keyringSigner, gasLimOption)
err = pfdMsg.SignShareCommitments(keyringSigner, gasLimOption)
if err != nil {
return err
}
Expand All @@ -130,7 +130,7 @@ if err != nil {
// for potential `MsgPayForData`s
signedTx, err := keyringSigner.BuildSignedTx(
gasLimOption(signer.NewTxBuilder()),
wpfmMsg,
wpfdMsg,
)
if err != nil {
return err
Expand Down
36 changes: 18 additions & 18 deletions x/payment/types/payfordata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,23 +210,23 @@ func TestSignMalleatedTxs(t *testing.T) {
}

for _, tt := range tests {
wpfm, err := NewWirePayForData(tt.ns, tt.msg, tt.ss...)
wpfd, err := NewWirePayForData(tt.ns, tt.msg, tt.ss...)
require.NoError(t, err, tt.name)
err = wpfm.SignShareCommitments(signer, tt.options...)
err = wpfd.SignShareCommitments(signer, tt.options...)
// there should be no error
assert.NoError(t, err)
// the signature should exist
assert.Equal(t, len(wpfm.MessageShareCommitment[0].Signature), 64)
assert.Equal(t, len(wpfd.MessageShareCommitment[0].Signature), 64)

// verify the signature for the PayForDatas derived from the
// WirePayForData
for i, size := range tt.ss {
unsignedPFM, err := wpfm.unsignedPayForData(size)
unsignedPFD, err := wpfd.unsignedPayForData(size)
require.NoError(t, err)

// create a new tx builder to create an unsigned PayForData
builder := applyOptions(signer.NewTxBuilder(), tt.options...)
tx, err := signer.BuildSignedTx(builder, unsignedPFM)
tx, err := signer.BuildSignedTx(builder, unsignedPFD)
require.NoError(t, err)

// Generate the bytes to be signed.
Expand All @@ -243,12 +243,12 @@ func TestSignMalleatedTxs(t *testing.T) {

// compare the commitments generated by the WirePayForData with
// that of independently generated PayForData
assert.Equal(t, unsignedPFM.MessageShareCommitment, wpfm.MessageShareCommitment[i].ShareCommitment)
assert.Equal(t, unsignedPFD.MessageShareCommitment, wpfd.MessageShareCommitment[i].ShareCommitment)

// verify the signature
assert.True(t, signer.GetSignerInfo().GetPubKey().VerifySignature(
bytesToSign,
wpfm.MessageShareCommitment[i].Signature,
wpfd.MessageShareCommitment[i].Signature,
),
fmt.Sprintf("test: %s size: %d", tt.name, size),
)
Expand Down Expand Up @@ -293,23 +293,23 @@ func TestProcessMessage(t *testing.T) {
ns: []byte{1, 1, 1, 1, 1, 1, 1, 2},
msg: bytes.Repeat([]byte{2}, ShareSize*15),
ss: 4,
modify: func(wpfm *MsgWirePayForData) *MsgWirePayForData {
wpfm.MessageShareCommitment[0].K = 99999
return wpfm
modify: func(wpfd *MsgWirePayForData) *MsgWirePayForData {
wpfd.MessageShareCommitment[0].K = 99999
return wpfd
},
expectErr: true,
},
}

for _, tt := range tests {
wpfm, err := NewWirePayForData(tt.ns, tt.msg, tt.ss)
wpfd, err := NewWirePayForData(tt.ns, tt.msg, tt.ss)
require.NoError(t, err, tt.name)
err = wpfm.SignShareCommitments(signer)
err = wpfd.SignShareCommitments(signer)
assert.NoError(t, err)

wpfm = tt.modify(wpfm)
wpfd = tt.modify(wpfd)

message, spfm, sig, err := ProcessWirePayForData(wpfm, tt.ss)
message, spfd, sig, err := ProcessWirePayForData(wpfd, tt.ss)
if tt.expectErr {
assert.Error(t, err, tt.name)
continue
Expand All @@ -318,10 +318,10 @@ func TestProcessMessage(t *testing.T) {
// ensure that the shared fields are identical
assert.Equal(t, tt.msg, message.Data, tt.name)
assert.Equal(t, tt.ns, message.NamespaceId, tt.name)
assert.Equal(t, wpfm.Signer, spfm.Signer, tt.name)
assert.Equal(t, wpfm.MessageNameSpaceId, spfm.MessageNamespaceId, tt.name)
assert.Equal(t, wpfm.MessageShareCommitment[0].ShareCommitment, spfm.MessageShareCommitment, tt.name)
assert.Equal(t, wpfm.MessageShareCommitment[0].Signature, sig, tt.name)
assert.Equal(t, wpfd.Signer, spfd.Signer, tt.name)
assert.Equal(t, wpfd.MessageNameSpaceId, spfd.MessageNamespaceId, tt.name)
assert.Equal(t, wpfd.MessageShareCommitment[0].ShareCommitment, spfd.MessageShareCommitment, tt.name)
assert.Equal(t, wpfd.MessageShareCommitment[0].Signature, sig, tt.name)
}
}

Expand Down
12 changes: 6 additions & 6 deletions x/payment/types/wirepayfordata.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ func (msg *MsgWirePayForData) GetSigners() []sdk.AccAddress {
// createPayForDataSignature generates the signature for a PayForData for a single square
// size using the info from a MsgWirePayForData
func (msg *MsgWirePayForData) createPayForDataSignature(signer *KeyringSigner, builder sdkclient.TxBuilder, k uint64) ([]byte, error) {
pfm, err := msg.unsignedPayForData(k)
pfd, err := msg.unsignedPayForData(k)
if err != nil {
return nil, err
}
tx, err := signer.BuildSignedTx(builder, pfm)
tx, err := signer.BuildSignedTx(builder, pfd)
if err != nil {
return nil, err
}
Expand All @@ -173,13 +173,13 @@ func (msg *MsgWirePayForData) unsignedPayForData(k uint64) (*MsgPayForData, erro
return nil, err
}

sPFM := MsgPayForData{
sPFD := MsgPayForData{
MessageNamespaceId: msg.MessageNameSpaceId,
MessageSize: msg.MessageSize,
MessageShareCommitment: commit,
Signer: msg.Signer,
}
return &sPFM, nil
return &sPFD, nil
}

// ProcessWirePayForData will perform the processing required by PreProcessTxs.
Expand Down Expand Up @@ -208,10 +208,10 @@ func ProcessWirePayForData(msg *MsgWirePayForData, squareSize uint64) (*tmproto.
}

// wrap the signed transaction data
pfm, err := msg.unsignedPayForData(squareSize)
pfd, err := msg.unsignedPayForData(squareSize)
if err != nil {
return nil, nil, nil, err
}

return &coreMsg, pfm, shareCommit.Signature, nil
return &coreMsg, pfd, shareCommit.Signature, nil
}
16 changes: 8 additions & 8 deletions x/payment/types/wirepayfordata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,34 @@ func TestWirePayForData_ValidateBasic(t *testing.T) {
wantErr *sdkerrors.Error
}

// valid pfm
// valid pfd
validMsg := validWirePayForData(t)

// pfm with bad ns id
// pfd with bad ns id
badIDMsg := validWirePayForData(t)
badIDMsg.MessageNameSpaceId = []byte{1, 2, 3, 4, 5, 6, 7}

// pfm that uses reserved ns id
// pfd that uses reserved ns id
reservedMsg := validWirePayForData(t)
reservedMsg.MessageNameSpaceId = []byte{0, 0, 0, 0, 0, 0, 0, 100}

// pfm that has a wrong msg size
// pfd that has a wrong msg size
invalidMsgSizeMsg := validWirePayForData(t)
invalidMsgSizeMsg.Message = bytes.Repeat([]byte{1}, consts.ShareSize-20)

// pfm that has a wrong msg size
// pfd that has a wrong msg size
invalidDeclaredMsgSizeMsg := validWirePayForData(t)
invalidDeclaredMsgSizeMsg.MessageSize = 999

// pfm with bad commitment
// pfd with bad commitment
badCommitMsg := validWirePayForData(t)
badCommitMsg.MessageShareCommitment[0].ShareCommitment = []byte{1, 2, 3, 4}

// pfm that has invalid square size (not power of 2)
// pfd that has invalid square size (not power of 2)
invalidSquareSizeMsg := validWirePayForData(t)
invalidSquareSizeMsg.MessageShareCommitment[0].K = 15

// pfm that has a different power of 2 square size
// pfd that has a different power of 2 square size
badSquareSizeMsg := validWirePayForData(t)
badSquareSizeMsg.MessageShareCommitment[0].K = 4

Expand Down

0 comments on commit 7978689

Please sign in to comment.