Skip to content

Conversation

@joanestebanr
Copy link
Collaborator

@joanestebanr joanestebanr commented Nov 17, 2025

  • Fix estimatedSize that must consided metadata as a Hash, not the length of bytes
  • Add a new RPC end-point for aggsender aggsender_triggerCertitificate to force a trigger certificate:
    This is a useful feature for testing or event can be used in production to don't wait a epoch to force a trigger
curl -X POST http://localhost:5576/ "Content-Type: application/json"   -d '{"method":"aggsender_triggerCertitificate", "params":[], "id":1}'

🔗 Related PRs

📝 Notes

  • [Optional: design decisions, tradeoffs, or TODOs]

- Fix estimatedSize that must consided metadata as a Hash, not the
length of bytes
- Add a new RPC end-point for aggsender `aggsender_triggerCertitificate`
to force a trigger certificate:
This is a useful feature for testing or event can be used in production
to don't wait a epoch to force a trigger
```
curl -X POST http://localhost:5576/ "Content-Type: application/json"   -d '{"method":"aggsender_triggerCertitificate", "params":[], "id":1}'
```
- #1296
@joanestebanr joanestebanr self-assigned this Nov 17, 2025
Comment on lines 194 to 195
r.mutex.Lock()
defer r.mutex.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

What are we trying to protect with this mutex? If it is the channel, it should be thread-safe by default (and also it is a bit strange setting it to nil in case of cancellation)...

We should only take care not to write into already closed channel in the ForceTriggerEvent (which if necessary we can track using some field of atomic.Bool value).

Copy link
Collaborator Author

@joanestebanr joanestebanr Nov 17, 2025

Choose a reason for hiding this comment

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

I agree, but I added the mutex because the tests where complaining about "data race".. I think that even the channel is thread-safe is not the member of the object 'ch' that requires to be protected to access it.
I remove the unneeded mutex

Copy link
Contributor

Choose a reason for hiding this comment

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

The pattern with using mutex together with channels is not necessary AFAIK.

I have tried removing the mutex field altogether and I cannot see any data race warnings in the output.

stefan@Stefan:~/go/src/Polygon/aggkit$ go test -race -count=20 github.com/agglayer/aggkit/aggsender
ok      github.com/agglayer/aggkit/aggsender    56.281s

Therefore I'm still suggesting to remove the mutex field. WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right is no longer complaining about data race!
How do you suggest to fix this code to guarantee that after if r.ch==nil is not modified the value until line r.ch <-...?

func (r *preconfTrigger) ForceTriggerEvent() {
	blockNumber, err := r.l2BridgeSync.GetLastProcessedBlock(context.Background())
	if err != nil {
		r.log.Errorf("ForceTriggerEvent: Failed to get last processed block: %v", err)
		return
	}
	r.mutex.Lock()
	defer r.mutex.Unlock()
	if r.ch == nil {
		return
	}
	r.ch <- aggkitsync.Block{Num: blockNumber}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

You can check if the channel is closed, before trying to write to it, which is if I'm not mistaken enough to protect yourself from writing into closed channel

_, ok := <-ch
if !ok {
    // Channel is closed and all buffered values have been received.
    fmt.Println("Channel is closed!")
}

Copy link
Collaborator Author

@joanestebanr joanestebanr Nov 18, 2025

Choose a reason for hiding this comment

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

But if it's closed beetween the check and sending data?

check_channel()
#  other gorotuine close channel
r.ch <- myData

I still think that we are not protected against that, but anyway, I have removed the mutex! cdab031

Copy link
Contributor

@Stefan-Ethernal Stefan-Ethernal left a comment

Choose a reason for hiding this comment

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

Generally LGTM

@sonarqubecloud
Copy link

@joanestebanr joanestebanr merged commit 299d6e3 into develop Nov 18, 2025
22 checks passed
@joanestebanr joanestebanr deleted the feat/cherrypick-1304-zkevm_migration_support-0_7_X branch November 18, 2025 14:48
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.

4 participants