neo-project / neo-modules

MIT License
61 stars 102 forks source link

Malformed `getapplicationlog` RPC request result #897

Closed AnnaShaleva closed 2 months ago

AnnaShaleva commented 3 months ago

Describe the bug While testing the https://github.com/nspcc-dev/neo-go/pull/3402, I discovered that ApplicationLogs plugin returns improper result of getapplicationlog RPC call. The result contains wrong contract field value of notifications section. For example, getapplicationlog for genesis block of mainnet has exactly the same notification's contract hash for all notificaitons (for both OnPersist and PostPersist triggers), 0xd2a4cff31913016155e38e474a2c06d08be276cf (native GasToken). While I'd expect contract hashes of notifications to have proper values.

This bug was introduced in master after 20th of March, because in that day I successfully built neo-modules master and checked genesis block notifications within the scope of https://github.com/neo-project/neo/issues/2834#issuecomment-2008142934. I'm suspecting that this bug was introduced by https://github.com/neo-project/neo-modules/pull/865, because this PR was merged 21th of March and makes a lot of changes in ApplicationLogs plugin, but we need to check.

To Reproduce Steps to reproduce the behavior:

  1. Build fresh neo-modules master and fresh NeoCLI;
  2. Run NeoCLI with RPCServer and ApplicationLogs plugin enabled and start mainnet sync from genesis;
  3. Send getapplicationlog RPC request to RPC server with genesis block hash;
  4. Check the result.

The result from the fresh master is:

anna@kiwi:~/Documents/GitProjects/neo-project/neo/src/Neo.CLI/bin/Release/net8.0/linux-x64$ curl -d '{ "jsonrpc": "2.0", "id": 1, "method": "getapplicationlog", "params": ["0x1f4d1defa46faa5e7b9b8d3f79a06bec777d7c26c4aa5f6f5899a291daa87c15"] }' localhost:10332 | json_pp
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2725    0  2583  100   142  49590   2726 --:--:-- --:--:-- --:--:-- 52403
{
   "id" : 1,
   "jsonrpc" : "2.0",
   "result" : {
      "blockhash" : "0x1f4d1defa46faa5e7b9b8d3f79a06bec777d7c26c4aa5f6f5899a291daa87c15",
      "executions" : [
         {
            "gasconsumed" : "0",
            "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="
                        }
                     ]
                  }
               }
            ],
            "stack" : [],
            "trigger" : "OnPersist",
            "vmstate" : "HALT"
         },
         {
            "gasconsumed" : "0",
            "notifications" : [
               {
                  "contract" : "0xd2a4cff31913016155e38e474a2c06d08be276cf",
                  "eventname" : "Transfer",
                  "state" : {
                     "type" : "Array",
                     "value" : [
                        {
                           "type" : "Any"
                        },
                        {
                           "type" : "ByteString",
                           "value" : "lpSe1ILnxgqu7GkVUPGz1ZkUYZQ="
                        },
                        {
                           "type" : "Integer",
                           "value" : "50000000"
                        }
                     ]
                  }
               }
            ],
            "stack" : [],
            "trigger" : "PostPersist",
            "vmstate" : "HALT"
         }
      ]
   }
}

Expected behavior The expected result is mentioned in https://github.com/neo-project/neo/issues/2834#issuecomment-2008142934, it should have proper contract hashes for all genesis notifications:

anna@kiwi:~/Documents/GitProjects/nspcc-dev/neo-go$ curl -d '{ "jsonrpc": "2.0", "id": 1, "method": "getapplicationlog", "params": ["0x1f4d1defa46faa5e7b9b8d3f79a06bec777d7c26c4aa5f6f5899a291daa87c15"] }' localhost:10332 | json_pp
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2725    0  2583  100   142   644k  36298 --:--:-- --:--:-- --:--:--  887k
{
   "id" : 1,
   "jsonrpc" : "2.0",
   "result" : {
      "blockhash" : "0x1f4d1defa46faa5e7b9b8d3f79a06bec777d7c26c4aa5f6f5899a291daa87c15",
      "executions" : [
         {
            "gasconsumed" : "0",
            "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="
                        }
                     ]
                  }
               }
            ],
            "stack" : [],
            "trigger" : "OnPersist",
            "vmstate" : "HALT"
         },
         {
            "gasconsumed" : "0",
            "notifications" : [
               {
                  "contract" : "0xd2a4cff31913016155e38e474a2c06d08be276cf",
                  "eventname" : "Transfer",
                  "state" : {
                     "type" : "Array",
                     "value" : [
                        {
                           "type" : "Any"
                        },
                        {
                           "type" : "ByteString",
                           "value" : "lpSe1ILnxgqu7GkVUPGz1ZkUYZQ="
                        },
                        {
                           "type" : "Integer",
                           "value" : "50000000"
                        }
                     ]
                  }
               }
            ],
            "stack" : [],
            "trigger" : "PostPersist",
            "vmstate" : "HALT"
         }
      ]
   }
}

Platform:

(Optional) Additional context

This bug is critical for 3.7, should be solved before the release.

cschuchardt88 commented 3 months ago

The cache is getting overwritten when using IStore.GetSnapshot with leveldb. Ill get a workaround going...