Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prototype: compact blocks #1191

Draft
wants to merge 75 commits into
base: v0.34.x-celestia
Choose a base branch
from
Draft

Conversation

cmwaters
Copy link
Contributor

No description provided.

@cmwaters cmwaters changed the title prototype: compact blocksCallum/compact blocks prototype: compact blocks Jan 25, 2024
Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leaving a few notes from debugging. no rush to get to these as some are just things we would have fixed after the prototype

Comment on lines 92 to 112
has := memR.mempool.store.has(key)
if !has {
// If the mempool provided the initial transactions yet received from
// consensus a transaction it doesn't recognize, this implies that
// either a tx was mutated or was added by the application. In either
// case, it is likely no other mempool has this transaction so we
// preemptively broadcast it to all other peers
//
// We don't set the priority, gasWanted or sender fields because we
// don't know them.
wtx := newWrappedTx(tx, key, memR.mempool.Height(), 0, 0, "")
memR.broadcastNewTx(wtx)
// For safety we also store this transaction in the mempool (ignoring
// all size limits) so that we can retrieve it later if needed. Note
// as we're broadcasting it to all peers, we should not receive a `WantTx`
// unless it gets rejected by the application in CheckTx.
//
// Consensus will have an in memory copy of the entire block which includes
// this transaction so it should not need it.
memR.mempool.store.set(wtx)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to call checktx to avoid accidently including invalid txs?

Comment on lines 62 to 65
timeTaken := request.TimeTaken()
if timeTaken == 0 {
return
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's for gathering metrics

Comment on lines +222 to +228
go func() {
reactor.ReceiveEnvelope(p2p.Envelope{
Src: peer,
Message: &memproto.Txs{Txs: txs},
ChannelID: mempool.MempoolChannel,
})
}()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we intenting to send all the txs to ourselves? I'm assuming no, since we are explicitly delaying the txs earlier and we can delete this and the test still passes.

Comment on lines +230 to +239
resultTxs, err := reactor.FetchTxsFromKeys(ctx, blockID, keys)
require.NoError(t, err)
require.Equal(t, len(txs), len(resultTxs))
for idx, tx := range resultTxs {
require.Equal(t, txs[idx], tx)
}
repeatResult, err := reactor.FetchTxsFromKeys(ctx, blockID, keys)
require.NoError(t, err)
require.Equal(t, resultTxs, repeatResult)
wg.Wait()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does repeating and comparing test? can we document this if its something not obvious or benign?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be to hit the cache

return nil
}

func (cs *State) addCompactBlock(msg *CompactBlockMessage, peerID p2p.ID) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need the peerID here, I guess we don't have that linter setup here

Suggested change
func (cs *State) addCompactBlock(msg *CompactBlockMessage, peerID p2p.ID) error {
func (cs *State) addCompactBlock(msg *CompactBlockMessage) error {

) (*types.Block, *types.PartSet) {
) *types.Block {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why get rid of the partset here?

Comment on lines 1236 to 1240
cs.sendInternalMessage(msgInfo{&ProposalMessage{proposal}, ""})
cs.sendInternalMessage(msgInfo{&CompactBlockMessage{
Block: block,
Round: p.Round,
}, ""})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after prototyping, just a little note here to just include the hashes in the canonical proposal to ensure that the hashes are not tampered

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

niche meme, but worth a shot
part of the burger

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after prototyping, just a little note here to just include the hashes in the canonical proposal to ensure that the hashes are not tampered

What do you mean by this?

Copy link
Member

@evan-forbes evan-forbes Mar 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the compact block signed over by the proposer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the user tries to construct the compact block and matches that to the proposal block ID which was signed over by the proposer

txs := make([][]byte, numTxs)
keys := make([][]byte, numTxs)
peer := genPeer()
blockID := tmhash.Sum([]byte("blockID"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the block id used to check anything or does it just serve as an index?

Comment on lines +74 to +76
FetchKeysFromTxs(context.Context, [][]byte) ([][]byte, error)
// For reconstructing the full block from the compact block
FetchTxsFromKeys(context.Context, []byte, [][]byte) ([][]byte, error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note for after prototype: we need var names plus more dovs here

mp.EnableTxsAvailable()
}
reactor.SetLogger(logger)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it won't let me highlight the part I want, the default will return nil (if not selecting v2 in the config), which could be confusing. The consensus reactor will pick a nil txFetcher, which uses will just return the keys instead of actually getting the txs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It assumes that compact blocks is not being used in which case the keys are the full transactions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants