neo-project / neo-modules

MIT License
61 stars 102 forks source link

Fix storage snapshot sync #898

Closed cschuchardt88 closed 2 months ago

cschuchardt88 commented 3 months ago

Change Log

Note: DO NOT need to resync

Closes #897

AnnaShaleva commented 3 months ago

Good job. Correct now.

@superboyiii, am I doing something wrong? Are you sure you've got the correct result?

superboyiii commented 3 months ago

Good job. Correct now.

@superboyiii, am I doing something wrong? Are you sure you've got the correct result?

My fault, wrong data was compared in test. Yes, the transfer event in OnPersist trigger should be for GAS and NEO, but not for 0xfffdc93764dbaddd97c48f252a53ea4643faa3fd(contract management) itself. @cschuchardt88 b07128561a78e300118a27a4fb9fcf1

cschuchardt88 commented 3 months ago

@AnnaShaleva @superboyiii

All check out but the block with hash of 0x1f4d1defa46faa5e7b9b8d3f79a06bec777d7c26c4aa5f6f5899a291daa87c15 and index of 0.

The reason for this is because NeoSystem gets initialized before any Plugins get loaded.

For example block with hash of 0x8e1db6017a1205501a8689ff1657ff81d264bca2e4afba12f673a8e4bad6bad2 checks out valid.

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "blockhash": "0x8e1db6017a1205501a8689ff1657ff81d264bca2e4afba12f673a8e4bad6bad2",
        "executions": [
            {
                "trigger": "OnPersist",
                "vmstate": "HALT",
                "gasconsumed": "0",
                "stack": [],
                "notifications": [
                    {
                        "contract": "0xd2a4cff31913016155e38e474a2c06d08be276cf",
                        "eventname": "Transfer",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "ByteString",
                                    "value": "axI92L7HGGSIUrvHhZXjU2oFj58="
                                },
                                {
                                    "type": "Any"
                                },
                                {
                                    "type": "Integer",
                                    "value": "17589000"
                                }
                            ]
                        }
                    },
                    {
                        "contract": "0xd2a4cff31913016155e38e474a2c06d08be276cf",
                        "eventname": "Transfer",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "Any"
                                },
                                {
                                    "type": "ByteString",
                                    "value": "UDiCgEgZdLrr634iF9YNyKdJeLo="
                                },
                                {
                                    "type": "Integer",
                                    "value": "7611220"
                                }
                            ]
                        }
                    }
                ]
            },
            {
                "trigger": "PostPersist",
                "vmstate": "HALT",
                "gasconsumed": "0",
                "stack": [],
                "notifications": [
                    {
                        "contract": "0xd2a4cff31913016155e38e474a2c06d08be276cf",
                        "eventname": "Transfer",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "Any"
                                },
                                {
                                    "type": "ByteString",
                                    "value": "lpSe1ILnxgqu7GkVUPGz1ZkUYZQ="
                                },
                                {
                                    "type": "Integer",
                                    "value": "50000000"
                                }
                            ]
                        }
                    }
                ]
            }
        ]
    }
}
AnnaShaleva commented 3 months ago

All check out but the block with hash of 0x1f4d1defa46faa5e7b9b8d3f79a06bec777d7c26c4aa5f6f5899a291daa87c15 and index of 0. The reason for this is because NeoSystem gets initialized before any Plugins get loaded.

@cschuchardt88, we need ApplicationLogs plugin to work correctly even for genesis block, it's important.

cschuchardt88 commented 3 months ago

@AnnaShaleva

This seems to be a problem with NeoSystem; the way plugins are loaded. I don't think genesis block requests block information from the network. What i see is happening; is that genesis block is initialized already before plugins get loaded and started. Maybe @Jim8y @shargon can you confirm?

@superboyiii @AnnaShaleva notifyItem.ScriptHash is valid and i get 0xfffdc93764dbaddd97c48f252a53ea4643faa3fd. That data is coming from straight from BlockChain.OnCommitting event; IReadOnlyList<Blockchain.ApplicationExecuted> applicationExecutedList parameter.

var notifyItem = appExecution.Notifications[i];
logStore.PutContractState(notifyItem.ScriptHash, block.Timestamp, i, ContractLogState.Create(appExecution, notifyItem, stackItemStateIds));
shargon commented 3 months ago

What i see is happening; is that genesis block is initialized already before plugins get loaded and started.

foreach (var plugin in Plugin.Plugins)
    plugin.OnSystemLoaded(this);
Blockchain.Ask(new Blockchain.Initialize()).Wait();

It seems that the plugin is called before it

cschuchardt88 commented 3 months ago

@shargon any reason why 0xfffdc93764dbaddd97c48f252a53ea4643faa3fd ContractManagement contract would be the hash for OnPersist trigger?

shargon commented 3 months ago

@shargon any reason why 0xfffdc93764dbaddd97c48f252a53ea4643faa3fd ContractManagement contract would be the hash for OnPersist trigger?

I don't understand you, could you explain it? the hash for OnPersist?

cschuchardt88 commented 3 months ago

@shargon When I receive applicationExecutedList from on Blockchain.Committing event I get the NotifyEventArgs and when accessing NotifyEventArgs.ScriptHash I am getting 0xfffdc93764dbaddd97c48f252a53ea4643faa3fd not 0xd2a4cff31913016155e38e474a2c06d08be276cf. Any thoughts?

Correct response

                    {
                        "contract": "0xd2a4cff31913016155e38e474a2c06d08be276cf",
                        "eventname": "Transfer",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "ByteString",
                                    "value": "axI92L7HGGSIUrvHhZXjU2oFj58="
                                },
                                {
                                    "type": "Any"
                                },
                                {
                                    "type": "Integer",
                                    "value": "17589000"
                                }
                            ]
                        }
                    }
cschuchardt88 commented 3 months ago

@AnnaShaleva @superboyiii Test again should be fixed now. There was a memory leak because the project isn't marked as nullable so when using a null ? and not making it ! after you get an object will have it keep overwriting/copying the same variable pointer when using out or ref.

Now I get:

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "blockhash": "0x1f4d1defa46faa5e7b9b8d3f79a06bec777d7c26c4aa5f6f5899a291daa87c15",
        "executions": [
            {
                "trigger": "OnPersist",
                "vmstate": "HALT",
                "gasconsumed": "0",
                "stack": [],
                "notifications": [
                    {
                        "contract": "0xd2a4cff31913016155e38e474a2c06d08be276cf",
                        "eventname": "Deploy",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "ByteString",
                                    "value": "/aP6Q0bqUyolj8SX3a3bZDfJ/f8="
                                }
                            ]
                        }
                    },
                    {
                        "contract": "0xd2a4cff31913016155e38e474a2c06d08be276cf",
                        "eventname": "Deploy",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "ByteString",
                                    "value": "wO85zuDk6SXGwqBqeeFEDdhvzqw="
                                }
                            ]
                        }
                    },
                    {
                        "contract": "0xd2a4cff31913016155e38e474a2c06d08be276cf",
                        "eventname": "Deploy",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "ByteString",
                                    "value": "G/V1qxGJaIQTYQo1oSiGzeC2bHI="
                                }
                            ]
                        }
                    },
                    {
                        "contract": "0xd2a4cff31913016155e38e474a2c06d08be276cf",
                        "eventname": "Deploy",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "ByteString",
                                    "value": "vvIEMUA2KnfBUJnH5kwS9wC2Zdo="
                                }
                            ]
                        }
                    },
                    {
                        "contract": "0xd2a4cff31913016155e38e474a2c06d08be276cf",
                        "eventname": "Transfer",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "Any"
                                },
                                {
                                    "type": "ByteString",
                                    "value": "axI92L7HGGSIUrvHhZXjU2oFj58="
                                },
                                {
                                    "type": "Integer",
                                    "value": "100000000"
                                }
                            ]
                        }
                    },
                    {
                        "contract": "0xd2a4cff31913016155e38e474a2c06d08be276cf",
                        "eventname": "Deploy",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "ByteString",
                                    "value": "9WPqQLwoPU0OBcSOowWz8qBzQO8="
                                }
                            ]
                        }
                    },
                    {
                        "contract": "0xd2a4cff31913016155e38e474a2c06d08be276cf",
                        "eventname": "Transfer",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "Any"
                                },
                                {
                                    "type": "ByteString",
                                    "value": "axI92L7HGGSIUrvHhZXjU2oFj58="
                                },
                                {
                                    "type": "Integer",
                                    "value": "5200000000000000"
                                }
                            ]
                        }
                    },
                    {
                        "contract": "0xd2a4cff31913016155e38e474a2c06d08be276cf",
                        "eventname": "Deploy",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "ByteString",
                                    "value": "z3bii9AGLEpHjuNVYQETGfPPpNI="
                                }
                            ]
                        }
                    },
                    {
                        "contract": "0xd2a4cff31913016155e38e474a2c06d08be276cf",
                        "eventname": "Deploy",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "ByteString",
                                    "value": "e8aBwKH3HVQ0V7aLuo1fn91OXsw="
                                }
                            ]
                        }
                    },
                    {
                        "contract": "0xd2a4cff31913016155e38e474a2c06d08be276cf",
                        "eventname": "Deploy",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "ByteString",
                                    "value": "4pXjkVRMF4rZTwPsTc3/eFNOz0k="
                                }
                            ]
                        }
                    },
                    {
                        "contract": "0xd2a4cff31913016155e38e474a2c06d08be276cf",
                        "eventname": "Deploy",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "ByteString",
                                    "value": "WIcXEX4KqBByr6tx0t2J/nxLkv4="
                                }
                            ]
                        }
                    }
                ]
            },
            {
                "trigger": "PostPersist",
                "vmstate": "HALT",
                "gasconsumed": "0",
                "stack": [],
                "notifications": [
                    {
                        "contract": "0xd2a4cff31913016155e38e474a2c06d08be276cf",
                        "eventname": "Transfer",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "Any"
                                },
                                {
                                    "type": "ByteString",
                                    "value": "lpSe1ILnxgqu7GkVUPGz1ZkUYZQ="
                                },
                                {
                                    "type": "Integer",
                                    "value": "50000000"
                                }
                            ]
                        }
                    }
                ]
            }
        ]
    }
}
superboyiii commented 2 months ago

@cschuchardt88 You could always check original one by v3.6.2 RPC:

curl -X POST http://seed1.neo.org:10332 -d '{"jsonrpc":"2.0","method":"getapplicationlog","params":["0x1f4d1defa46faa5e7b9b8d3f79a06bec777d7c26c4aa5f6f5899a291daa87c15"],"id":1}'

Your current result mistakenly got wrong contract hash for NEO(Not GAS). As we all know 100000000 NEO and 52000000 GAS has been transferred into consensus multisig address in genesis block. That's where these 2 transfer events from.

cschuchardt88 commented 2 months ago

@AnnaShaleva @superboyiii

My bad forgot to commit.

http://seed1.neo.org:10332

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "blockhash": "0x1f4d1defa46faa5e7b9b8d3f79a06bec777d7c26c4aa5f6f5899a291daa87c15",
        "executions": [
            {
                "trigger": "OnPersist",
                "vmstate": "HALT",
                "gasconsumed": "0",
                "stack": [],
                "notifications": [
                    {
                        "contract": "0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5",
                        "eventname": "Transfer",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "Any"
                                },
                                {
                                    "type": "ByteString",
                                    "value": "axI92L7HGGSIUrvHhZXjU2oFj58="
                                },
                                {
                                    "type": "Integer",
                                    "value": "100000000"
                                }
                            ]
                        }
                    },
                    {
                        "contract": "0xd2a4cff31913016155e38e474a2c06d08be276cf",
                        "eventname": "Transfer",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "Any"
                                },
                                {
                                    "type": "ByteString",
                                    "value": "axI92L7HGGSIUrvHhZXjU2oFj58="
                                },
                                {
                                    "type": "Integer",
                                    "value": "5200000000000000"
                                }
                            ]
                        }
                    }
                ]
            },
            {
                "trigger": "PostPersist",
                "vmstate": "HALT",
                "gasconsumed": "0",
                "stack": [],
                "notifications": [
                    {
                        "contract": "0xd2a4cff31913016155e38e474a2c06d08be276cf",
                        "eventname": "Transfer",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "Any"
                                },
                                {
                                    "type": "ByteString",
                                    "value": "lpSe1ILnxgqu7GkVUPGz1ZkUYZQ="
                                },
                                {
                                    "type": "Integer",
                                    "value": "50000000"
                                }
                            ]
                        }
                    }
                ]
            }
        ]
    }
}

http://127.0.0.1:10332

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "blockhash": "0x1f4d1defa46faa5e7b9b8d3f79a06bec777d7c26c4aa5f6f5899a291daa87c15",
        "executions": [
            {
                "trigger": "OnPersist",
                "vmstate": "HALT",
                "gasconsumed": "0",
                "stack": [],
                "notifications": [
                    {
                        "contract": "0xfffdc93764dbaddd97c48f252a53ea4643faa3fd",
                        "eventname": "Deploy",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "ByteString",
                                    "value": "/aP6Q0bqUyolj8SX3a3bZDfJ/f8="
                                }
                            ]
                        }
                    },
                    {
                        "contract": "0xfffdc93764dbaddd97c48f252a53ea4643faa3fd",
                        "eventname": "Deploy",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "ByteString",
                                    "value": "wO85zuDk6SXGwqBqeeFEDdhvzqw="
                                }
                            ]
                        }
                    },
                    {
                        "contract": "0xfffdc93764dbaddd97c48f252a53ea4643faa3fd",
                        "eventname": "Deploy",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "ByteString",
                                    "value": "G/V1qxGJaIQTYQo1oSiGzeC2bHI="
                                }
                            ]
                        }
                    },
                    {
                        "contract": "0xfffdc93764dbaddd97c48f252a53ea4643faa3fd",
                        "eventname": "Deploy",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "ByteString",
                                    "value": "vvIEMUA2KnfBUJnH5kwS9wC2Zdo="
                                }
                            ]
                        }
                    },
                    {
                        "contract": "0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5",
                        "eventname": "Transfer",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "Any"
                                },
                                {
                                    "type": "ByteString",
                                    "value": "axI92L7HGGSIUrvHhZXjU2oFj58="
                                },
                                {
                                    "type": "Integer",
                                    "value": "100000000"
                                }
                            ]
                        }
                    },
                    {
                        "contract": "0xfffdc93764dbaddd97c48f252a53ea4643faa3fd",
                        "eventname": "Deploy",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "ByteString",
                                    "value": "9WPqQLwoPU0OBcSOowWz8qBzQO8="
                                }
                            ]
                        }
                    },
                    {
                        "contract": "0xd2a4cff31913016155e38e474a2c06d08be276cf",
                        "eventname": "Transfer",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "Any"
                                },
                                {
                                    "type": "ByteString",
                                    "value": "axI92L7HGGSIUrvHhZXjU2oFj58="
                                },
                                {
                                    "type": "Integer",
                                    "value": "5200000000000000"
                                }
                            ]
                        }
                    },
                    {
                        "contract": "0xfffdc93764dbaddd97c48f252a53ea4643faa3fd",
                        "eventname": "Deploy",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "ByteString",
                                    "value": "z3bii9AGLEpHjuNVYQETGfPPpNI="
                                }
                            ]
                        }
                    },
                    {
                        "contract": "0xfffdc93764dbaddd97c48f252a53ea4643faa3fd",
                        "eventname": "Deploy",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "ByteString",
                                    "value": "e8aBwKH3HVQ0V7aLuo1fn91OXsw="
                                }
                            ]
                        }
                    },
                    {
                        "contract": "0xfffdc93764dbaddd97c48f252a53ea4643faa3fd",
                        "eventname": "Deploy",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "ByteString",
                                    "value": "4pXjkVRMF4rZTwPsTc3/eFNOz0k="
                                }
                            ]
                        }
                    },
                    {
                        "contract": "0xfffdc93764dbaddd97c48f252a53ea4643faa3fd",
                        "eventname": "Deploy",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "ByteString",
                                    "value": "WIcXEX4KqBByr6tx0t2J/nxLkv4="
                                }
                            ]
                        }
                    }
                ]
            },
            {
                "trigger": "PostPersist",
                "vmstate": "HALT",
                "gasconsumed": "0",
                "stack": [],
                "notifications": [
                    {
                        "contract": "0xd2a4cff31913016155e38e474a2c06d08be276cf",
                        "eventname": "Transfer",
                        "state": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "Any"
                                },
                                {
                                    "type": "ByteString",
                                    "value": "lpSe1ILnxgqu7GkVUPGz1ZkUYZQ="
                                },
                                {
                                    "type": "Integer",
                                    "value": "50000000"
                                }
                            ]
                        }
                    }
                ]
            }
        ]
    }
}
cschuchardt88 commented 2 months ago

@AnnaShaleva @superboyiii any update on testing the state?