RGB-WG / rgb-core

RGB Core Library: consensus validation for private & scalable client-validated smart contracts on Bitcoin & Lightning
https://spec.rgb.tech
Apache License 2.0
207 stars 52 forks source link

Avoid repeated state transition validation #128

Closed zoedberg closed 1 year ago

zoedberg commented 1 year ago

This PR fixes https://github.com/RGB-WG/rgb-core/issues/122 by adding a memory index.

The fix may be improved, but we decided to do the minimal possible fix that doesn't break APIs or change the code logic too much.

I don't think much more effort is needed here since there is already https://github.com/RGB-WG/rgb-core/issues/123 which purpose is to make a much bigger improvement and that will happen when breaking changes will be possible.

dr-orlovsky commented 1 year ago

This is for sure an improvement (and I am going to merge it), but it seems this is not a solution addressing problem from #122

It seems this code avoids repeated validation that state transition is a part of the anchor - but not the validation that the bitcoin transaction commits to the anchor (which what takes an electrum call).

zoedberg commented 1 year ago

@dr-orlovsky Are you sure about this? Looking at the code the only call to electrum I see is here, in validate_graph_node, which is being called only here, in validate_branch, inside the if clause where I added the new memory index.

Some calls that check the anchor against the bundle are still repeated but those should not use electrum, so I think we can address those as part of https://github.com/RGB-WG/rgb-core/issues/123.

dr-orlovsky commented 1 year ago

Oh right, I visually missed the call to validate_graph_node focusing on anchor.convolve one, thinking it was the call optimized. Than you are right!