c4dt / d-voting

📧 E-Voting platform based on the Dela blockchain
https://dedis.github.io/d-voting
BSD 3-Clause "New" or "Revised" License
1 stars 1 forks source link

Don't execute smartcontracts twice on the leader #56

Open ineiti opened 11 months ago

ineiti commented 11 months ago

Currently the leader executes each smartcontract twice. Probably once to know if the contract is legit, and then once with the doPBFT method.

It should execute the contract only once. Either use the result of this run, or only run it in the doPBFT method.

pierluca commented 9 months ago

I believe this is because the whole Dela software doesn't treat one's own node differently from the other nodes. As such, when something needs to be processed by all nodes, it'll be sent for all nodes to process.

In this particular case, I suspect the leader executes the contract once, when building a block and before proposing it to all the nodes (incl. itself), then a second time once the block is sent to all the nodes (incl. the leader itself) for validation/integration in the blockchain.

ineiti commented 9 months ago

So there should be a cache to avoid executing the contract twice.

I'm not sure if my calculations are exact. But even for the worst case (meaning my calculations were right), voting time would go down from 100ms to 80ms. So I don't think it's worth it. But I keep it around in case we do need this small speedup.

PascalinDe commented 3 weeks ago

is this still an issue?

ineiti commented 3 weeks ago

It is an issue, but currently "premature optimization" :) If there are very slow smart contracts, it can double the transactions per second.