• Felföldi Zsolt's avatar
    p2p/nodestate: ensure correct callback order (#21436) · 4eb92969
    Felföldi Zsolt authored
    This PR adds an extra guarantee to NodeStateMachine: it ensures that all
    immediate effects of a certain change are processed before any subsequent
    effects of any of the immediate effects on the same node. In the original
    version, if a cascaded change caused a subscription callback to be called
    multiple times for the same node then these calls might have happened in a
    wrong chronological order.
    
    For example:
    
    - a subscription to flag0 changes flag1 and flag2
    - a subscription to flag1 changes flag3
    - a subscription to flag1, flag2 and flag3 was called in the following order:
    
       [flag1] -> [flag1, flag3]
       [] -> [flag1]
       [flag1, flag3] -> [flag1, flag2, flag3]
    
    This happened because the tree of changes was traversed in a "depth-first
    order". Now it is traversed in a "breadth-first order"; each node has a
    FIFO queue for pending callbacks and each triggered subscription callback
    is added to the end of the list. The already existing guarantees are
    retained; no SetState or SetField returns until the callback queue of the
    node is empty again. Just like before, it is the responsibility of the
    state machine design to ensure that infinite state loops are not possible.
    Multiple changes affecting the same node can still happen simultaneously;
    in this case the changes can be interleaved in the FIFO of the node but the
    correct order is still guaranteed.
    
    A new unit test is also added to verify callback order in the above scenario.
    4eb92969
Name
Last commit
Last update
.github Loading commit data...
accounts Loading commit data...
build Loading commit data...
cmd Loading commit data...
common Loading commit data...
consensus Loading commit data...
console Loading commit data...
contracts/checkpointoracle Loading commit data...
core Loading commit data...
crypto Loading commit data...
docs/audits Loading commit data...
eth Loading commit data...
ethclient Loading commit data...
ethdb Loading commit data...
ethstats Loading commit data...
event Loading commit data...
graphql Loading commit data...
internal Loading commit data...
les Loading commit data...
light Loading commit data...
log Loading commit data...
metrics Loading commit data...
miner Loading commit data...
mobile Loading commit data...
node Loading commit data...
p2p Loading commit data...
params Loading commit data...
rlp Loading commit data...
rpc Loading commit data...
signer Loading commit data...
swarm Loading commit data...
tests Loading commit data...
trie Loading commit data...
.dockerignore Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
.gitmodules Loading commit data...
.golangci.yml Loading commit data...
.mailmap Loading commit data...
.travis.yml Loading commit data...
AUTHORS Loading commit data...
COPYING Loading commit data...
COPYING.LESSER Loading commit data...
Dockerfile Loading commit data...
Dockerfile.alltools Loading commit data...
Makefile Loading commit data...
README.md Loading commit data...
SECURITY.md Loading commit data...
appveyor.yml Loading commit data...
circle.yml Loading commit data...
fuzzbuzz.yaml Loading commit data...
go.mod Loading commit data...
go.sum Loading commit data...
interfaces.go Loading commit data...