Skip to content

Blob channel#12753

Merged
potuz merged 7 commits intodeneb-integrationfrom
blob_channel
Aug 18, 2023
Merged

Blob channel#12753
potuz merged 7 commits intodeneb-integrationfrom
blob_channel

Conversation

@potuz
Copy link
Contributor

@potuz potuz commented Aug 17, 2023

Adds a new channel to the blockchain package to keep track of blobs that have been added to database.

It's an unbuffered channel that notifies the blob sidecar's blockroot.

When processing blocks, if the blob is not in the database, we block until the channel receives the right blockroot or the slot context deadline is done.

The channel is unbuffered since blobs are always consumed by blocks.

@potuz potuz requested review from a team and prestonvanloon as code owners August 17, 2023 12:12
@potuz potuz requested review from rauljordan and rkapka August 17, 2023 12:12
@potuz potuz changed the base branch from develop to deneb-integration August 17, 2023 12:14
for {
select {
case <-nc.channel:
if len(kzgCommitments) == len(nc.indices) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you mean to make chanForRoot a map[[32]*blobNotifierChan? As currently written, nc.indices will never be updated by the blob side, because the read from the map makes a copy of the blobNotifierChan struct, so the slice append modifies the local copy. Using references on both sides will fix that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

for thread safety i think you want also treat the slice length computation as the critical section. or to avoid that lock, and since you aren't looking at the indices and are just checking the length, you could count how many times you read from the channel and change this if statement to len(kzCommitments) == nChannelReads. that would also clean up the writers to the channel, which could be leaking as currently written, because you could delete the blobNotifierChan without reading and unblocking them.

// for the blocroot `root` is ready in the database
func (s *Service) SendNewBlobEvent(root [32]byte, index uint64) {
s.blobNotifier.Lock()
defer s.blobNotifier.Unlock()
Copy link
Collaborator

Choose a reason for hiding this comment

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

you're holding the lock until the read happens, which will deadlock the reader that needs to hold the lock before it gets to the channel read code.

s.blobNotifier.chanForRoot[root] = nc
} else {
if !slice.IsInUint64(index, nc.indices) {
nc.indices = append(nc.indices, index)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this shouldn't be in an else, you'll miss the first index where the map entry is created

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the index was added in that creation as well wasn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh right the problem is if it's created in the reader

func (s *Service) SendNewBlobEvent(root [32]byte, index uint64) {
s.blobNotifier.Lock()
var ok bool
var nc *blobNotifierChan
Copy link
Collaborator

Choose a reason for hiding this comment

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

you could get rid of this pre-declaration

Copy link
Collaborator

@kasey kasey left a comment

Choose a reason for hiding this comment

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

lgtm!

@potuz potuz merged commit a01eec2 into deneb-integration Aug 18, 2023
@potuz potuz deleted the blob_channel branch August 18, 2023 00:03
kasey pushed a commit that referenced this pull request Aug 21, 2023
* Add a new blob channel

* fix mock

* reset the channel

* keep a map of channels

* gazelle

* do not overwrite map

* remove pre-declaration
kasey pushed a commit that referenced this pull request Aug 22, 2023
* Add a new blob channel

* fix mock

* reset the channel

* keep a map of channels

* gazelle

* do not overwrite map

* remove pre-declaration
kasey pushed a commit that referenced this pull request Aug 22, 2023
* Add a new blob channel

* fix mock

* reset the channel

* keep a map of channels

* gazelle

* do not overwrite map

* remove pre-declaration
kasey pushed a commit that referenced this pull request Aug 22, 2023
* Add a new blob channel

* fix mock

* reset the channel

* keep a map of channels

* gazelle

* do not overwrite map

* remove pre-declaration
kasey pushed a commit that referenced this pull request Aug 23, 2023
* Add a new blob channel

* fix mock

* reset the channel

* keep a map of channels

* gazelle

* do not overwrite map

* remove pre-declaration
kasey pushed a commit that referenced this pull request Aug 23, 2023
* Add a new blob channel

* fix mock

* reset the channel

* keep a map of channels

* gazelle

* do not overwrite map

* remove pre-declaration
kasey pushed a commit that referenced this pull request Aug 23, 2023
* Add a new blob channel

* fix mock

* reset the channel

* keep a map of channels

* gazelle

* do not overwrite map

* remove pre-declaration
kasey pushed a commit that referenced this pull request Aug 24, 2023
* Add a new blob channel

* fix mock

* reset the channel

* keep a map of channels

* gazelle

* do not overwrite map

* remove pre-declaration
kasey pushed a commit that referenced this pull request Aug 24, 2023
* Add a new blob channel

* fix mock

* reset the channel

* keep a map of channels

* gazelle

* do not overwrite map

* remove pre-declaration
prestonvanloon pushed a commit that referenced this pull request Aug 24, 2023
* Add a new blob channel

* fix mock

* reset the channel

* keep a map of channels

* gazelle

* do not overwrite map

* remove pre-declaration
prestonvanloon pushed a commit that referenced this pull request Aug 24, 2023
* Add a new blob channel

* fix mock

* reset the channel

* keep a map of channels

* gazelle

* do not overwrite map

* remove pre-declaration
prestonvanloon pushed a commit that referenced this pull request Aug 24, 2023
* Add a new blob channel

* fix mock

* reset the channel

* keep a map of channels

* gazelle

* do not overwrite map

* remove pre-declaration
prestonvanloon pushed a commit that referenced this pull request Aug 24, 2023
* Add a new blob channel

* fix mock

* reset the channel

* keep a map of channels

* gazelle

* do not overwrite map

* remove pre-declaration
prestonvanloon pushed a commit that referenced this pull request Aug 24, 2023
* Add a new blob channel

* fix mock

* reset the channel

* keep a map of channels

* gazelle

* do not overwrite map

* remove pre-declaration
prestonvanloon pushed a commit that referenced this pull request Aug 24, 2023
* Add a new blob channel

* fix mock

* reset the channel

* keep a map of channels

* gazelle

* do not overwrite map

* remove pre-declaration
prestonvanloon pushed a commit that referenced this pull request Aug 24, 2023
* Add a new blob channel

* fix mock

* reset the channel

* keep a map of channels

* gazelle

* do not overwrite map

* remove pre-declaration
prestonvanloon pushed a commit that referenced this pull request Aug 24, 2023
* Add a new blob channel

* fix mock

* reset the channel

* keep a map of channels

* gazelle

* do not overwrite map

* remove pre-declaration
prestonvanloon pushed a commit that referenced this pull request Aug 24, 2023
* Add a new blob channel

* fix mock

* reset the channel

* keep a map of channels

* gazelle

* do not overwrite map

* remove pre-declaration
prestonvanloon pushed a commit that referenced this pull request Aug 24, 2023
* Add a new blob channel

* fix mock

* reset the channel

* keep a map of channels

* gazelle

* do not overwrite map

* remove pre-declaration
prestonvanloon pushed a commit that referenced this pull request Aug 24, 2023
* Add a new blob channel

* fix mock

* reset the channel

* keep a map of channels

* gazelle

* do not overwrite map

* remove pre-declaration
prestonvanloon pushed a commit that referenced this pull request Aug 30, 2023
* Add a new blob channel

* fix mock

* reset the channel

* keep a map of channels

* gazelle

* do not overwrite map

* remove pre-declaration
prestonvanloon pushed a commit that referenced this pull request Aug 30, 2023
* Add a new blob channel

* fix mock

* reset the channel

* keep a map of channels

* gazelle

* do not overwrite map

* remove pre-declaration
prestonvanloon pushed a commit that referenced this pull request Aug 31, 2023
* Add a new blob channel

* fix mock

* reset the channel

* keep a map of channels

* gazelle

* do not overwrite map

* remove pre-declaration
var ErrMissingClockSetter = errors.New("blockchain Service initialized without a startup.ClockSetter")

type blobNotifierChan struct {
indices map[uint64]struct{}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need a map? it seems like a counter should be sufficient

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see. We are worried about duplication, but p2p validation should block that

Comment on lines -522 to -523
if err != nil {
return errors.Wrap(err, "could not get blob sidecars")
Copy link
Collaborator

Choose a reason for hiding this comment

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

If err is not nil, shouldn't we also do something like return early?

Copy link
Collaborator

Choose a reason for hiding this comment

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

nvm, I think this is by design, perhaps it's safer to check the error for not found

s.blobNotifier.Lock()
var nc *blobNotifierChan
var ok bool
nc, ok = s.blobNotifier.chanForRoot[root]
Copy link
Collaborator

@terencechain terencechain Sep 5, 2023

Choose a reason for hiding this comment

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

Can move this line before right before if !ok

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.

3 participants