neo icon indicating copy to clipboard operation
neo copied to clipboard

Emit "Deploy" notification for native contracts

Open roman-khimov opened this issue 3 years ago • 3 comments

Summary or problem description Native contracts are deployed by ContractManagement's OnPersist method, but what this method does is just pushing contract state to the DB. For regular contracts we have events generated as well since #2150, while there are no such events for native contracts. Of course they're not critical as of now, we know these contracts well and they're only changed at the genesis block, however this makes native contracts somewhat inconsistent with the regular ones and also can be a problem if we're to ever use NativeUpdateHistory feature with updates made to native contracts at some non-zero blocks.

Do you have any solution you want to propose? Emit "Deploy"/"Update" events for native contracts.

Neo Version

  • Neo 3

Where in the software does this update applies to?

  • ContractManagement native contract

roman-khimov avatar Dec 07 '22 15:12 roman-khimov

Looks like this was fixed in #2942.

roman-khimov avatar Mar 04 '24 19:03 roman-khimov

@roman-khimov close?

shargon avatar Mar 05 '24 08:03 shargon

It'd be perfect if anyone with the current master node and ApplicationLogs (@superboyiii?) could check that the event is indeed present where we expect it (genesis block persist). The code is very convincing to me, but still a quick check before closing won't hurt.

roman-khimov avatar Mar 05 '24 10:03 roman-khimov

I've checked the current master (b05501af882a0d1f2a1a7841c6ddc4d0504e5fc1), the genesis application log for OnPersist trigger contains required Deploy notifications for all 9 contracts, so it works as expected. It also contains required Transfer events.

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"
         }
      ]
   }
}

Just for the record, here's Base64-encoded hashes of native contracts retrieved from Go script:

ContractManagement: /aP6Q0bqUyolj8SX3a3bZDfJ/f8=
LedgerContract: vvIEMUA2KnfBUJnH5kwS9wC2Zdo=
NeoToken: 9WPqQLwoPU0OBcSOowWz8qBzQO8=
GasToken: z3bii9AGLEpHjuNVYQETGfPPpNI=
PolicyContract: e8aBwKH3HVQ0V7aLuo1fn91OXsw=
OracleContract: WIcXEX4KqBByr6tx0t2J/nxLkv4=
RoleManagement: 4pXjkVRMF4rZTwPsTc3/eFNOz0k=
Notary: O+w1MRGbutdt0ESSCw3mwxlP4cE=
CryptoLib: G/V1qxGJaIQTYQo1oSiGzeC2bHI=
StdLib: wO85zuDk6SXGwqBqeeFEDdhvzqw=

And also if needed, then here's the current application logs (for OnPersist and PostPersist) for the current mainnet genesis block:

anna@kiwi:~/Documents/GitProjects/nspcc-dev/neo-go$ curl -d '{ "jsonrpc": "2.0", "id": 1, "method": "getapplicationlog", "params": ["0x1f4d1defa46faa5e7b9b8d3f79a06bec777d7c26c4aa5f6f5899a291daa87c15"] }' http://seed1.neo.org:10332 | json_pp
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1150    0  1008  100   142   2424    341 --:--:-- --:--:-- --:--:--  2764
{
   "id" : 1,
   "jsonrpc" : "2.0",
   "result" : {
      "blockhash" : "0x1f4d1defa46faa5e7b9b8d3f79a06bec777d7c26c4aa5f6f5899a291daa87c15",
      "executions" : [
         {
            "gasconsumed" : "0",
            "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"
                        }
                     ]
                  }
               }
            ],
            "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"
         }
      ]
   }
}

AnnaShaleva avatar Mar 19 '24 21:03 AnnaShaleva

So this issue can be closed as completed.

AnnaShaleva avatar Mar 19 '24 21:03 AnnaShaleva

               {
                  "contract" : "0xfffdc93764dbaddd97c48f252a53ea4643faa3fd",
                  "eventname" : "Deploy",
                  "state" : {
                     "type" : "Array",
                     "value" : [
                        {
                           "type" : "ByteString",
                           "value" : "/aP6Q0bqUyolj8SX3a3bZDfJ/f8="
                        }
                     ]
                  }
               },

Contract 0xfffdc93764dbaddd97c48f252a53ea4643faa3fd says it has deployed contract 0xfffdc93764dbaddd97c48f252a53ea4643faa3fd, nice.

roman-khimov avatar Mar 20 '24 08:03 roman-khimov