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

Syncer: Logic for conditional broadcast #750

Merged
merged 3 commits into from
Dec 5, 2022

Conversation

TheCharlatan
Copy link
Member

This delays a transaction broadcast to after a certain block height has been reached.

This allows patterns as described in the CCS: "swap-daemon can queue tasks such as execute refund path at block height X with a chain-syncer."

@TheCharlatan TheCharlatan added the enhancement New feature or request label Nov 3, 2022
This delays a transaction broadcast to after a certain block height has been reached
@TheCharlatan TheCharlatan linked an issue Nov 3, 2022 that may be closed by this pull request
Copy link
Member

@h4sh3d h4sh3d left a comment

Choose a reason for hiding this comment

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

If I got it right the current logic always wait on a new block to trigger the broadcast even if the the height is smaller to current height. I get that the height should always be in the future but I wouldn't rely on this assumption. (In its current form is fine as we always use None but one might be tricked in the future)

@TheCharlatan
Copy link
Member Author

If I got it right the current logic always wait on a new block to trigger the broadcast even if the the height is smaller to current height.

It does trigger the iterator, but there is still a height check during the iteration. I wanted to keep the changes to the logic as minimal as possible here, but if you think this is too wasteful, I'd gladly refactor.

@h4sh3d
Copy link
Member

h4sh3d commented Dec 2, 2022

Whops I think I explained badly what my concern is. When a transaction broadcast arrives in syncer and the broadcast has an height attached we don't check if it is already broadcastable.

I'd see something like

if les Some(height) = task.broadcast_after_height {
    if height < current_height {
        // bradocast now
    } else {
        // add to pending
    }
} else { ... }

Or I didn't understand your explanation and you can forget all of this :)

Otherwise this LGTM!

@TheCharlatan
Copy link
Member Author

Whops I think I explained badly what my concern is. When a transaction broadcast arrives in syncer and the broadcast has an height attached we don't check if it is already broadcastable.

Ah, now I go it! Yes, that's a silly limitation. I was thinking the producer of a broadcast task would naturally be subscribed to the block height, but that is not exactly defensive. I'll add some code to check the height when the task comes in and immediately broadcast it in case we already surpassed it.

@h4sh3d h4sh3d self-assigned this Dec 5, 2022
@h4sh3d h4sh3d merged commit 01d6378 into farcaster-project:main Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Syncer: Add conditional tx broadcast logic
2 participants