mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-21 23:29:38 +00:00
block: add PrimaryIndex to the stack item of block
This is a bad one. $ ./bin/neo-go contract testinvokefunction -r https://rpc10.n3.nspcc.ru:10331 0xda65b600f7124ce6c79950c1772a36403104f2be getBlock 5762000 { "state": "HALT", "gasconsumed": "202812", "script": "AtDrVwARwB8MCGdldEJsb2NrDBS+8gQxQDYqd8FQmcfmTBL3ALZl2kFifVtS", "stack": [ { "type": "Array", "value": [ { "type": "ByteString", "value": "vq5IPTPEDRhz0JA4cQKIa6/o97pnJt/HfVkDRknd1rg=" }, { "type": "Integer", "value": "0" }, { "type": "ByteString", "value": "zFYF3LGaTKdbqVX99shaBUzTq9YjXb0jaPMjk2jdSP4=" }, { "type": "ByteString", "value": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" }, { "type": "Integer", "value": "1722060076994" }, { "type": "Integer", "value": "5293295626238767595" }, { "type": "Integer", "value": "5762000" }, { "type": "ByteString", "value": "LIt05Fpxhl/kXMX3EAGIASyOSQs=" }, { "type": "Integer", "value": "0" } ] } ], "exception": null, "notifications": [] } $ ./bin/neo-go contract testinvokefunction -r http://seed3.neo.org:10332 0xda65b600f7124ce6c79950c1772a36403104f2be getBlock 5762000 { "state": "HALT", "gasconsumed": "202812", "script": "AtDrVwARwB8MCGdldEJsb2NrDBS+8gQxQDYqd8FQmcfmTBL3ALZl2kFifVtS", "stack": [ { "type": "Array", "value": [ { "type": "ByteString", "value": "vq5IPTPEDRhz0JA4cQKIa6/o97pnJt/HfVkDRknd1rg=" }, { "type": "Integer", "value": "0" }, { "type": "ByteString", "value": "zFYF3LGaTKdbqVX99shaBUzTq9YjXb0jaPMjk2jdSP4=" }, { "type": "ByteString", "value": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" }, { "type": "Integer", "value": "1722060076994" }, { "type": "Integer", "value": "5293295626238767595" }, { "type": "Integer", "value": "5762000" }, { "type": "Integer", "value": "6" }, { "type": "ByteString", "value": "LIt05Fpxhl/kXMX3EAGIASyOSQs=" }, { "type": "Integer", "value": "0" } ] } ], "exception": null, "notifications": [] } 9 fields vs 10, notice the primary index right after the block number. Back whenac527650eb
initially added Ledger I've used https://github.com/neo-project/neo/pull/2215 as a reference and it was correct (no primary index). But then https://github.com/neo-project/neo/pull/2296 came into the C# codebase and while it looked like a pure refactoring it actually did add the primary index as well and this wasn't noticed. It wasn't noticed even when3a4e0caeb8
had touched some nearby code. In short, we had a completely wrong implementation of this call for more than three years. But looks like it's not a very popular one. Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
parent
c6ed92a169
commit
1a48f1ce43
3 changed files with 5 additions and 0 deletions
|
@ -229,6 +229,7 @@ func (b *Block) ToStackItem() stackitem.Item {
|
|||
stackitem.NewBigInteger(big.NewInt(int64(b.Timestamp))),
|
||||
stackitem.NewBigInteger(new(big.Int).SetUint64(b.Nonce)),
|
||||
stackitem.NewBigInteger(big.NewInt(int64(b.Index))),
|
||||
stackitem.NewBigInteger(big.NewInt(int64(b.PrimaryIndex))),
|
||||
stackitem.NewByteArray(b.NextConsensus.BytesBE()),
|
||||
stackitem.NewBigInteger(big.NewInt(int64(len(b.Transactions)))),
|
||||
}
|
||||
|
|
|
@ -159,6 +159,7 @@ func TestLedger_GetBlock(t *testing.T) {
|
|||
stackitem.NewBigInteger(big.NewInt(int64(b.Timestamp))),
|
||||
stackitem.NewBigInteger(big.NewInt(int64(b.Nonce))),
|
||||
stackitem.NewBigInteger(big.NewInt(int64(b.Index))),
|
||||
stackitem.NewBigInteger(big.NewInt(int64(b.PrimaryIndex))),
|
||||
stackitem.NewByteArray(b.NextConsensus.BytesBE()),
|
||||
stackitem.NewBigInteger(big.NewInt(int64(len(b.Transactions)))),
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ type Block struct {
|
|||
Nonce int
|
||||
// Index represents the height of the block.
|
||||
Index int
|
||||
// PrimaryIndex represents the index of the primary node that created this block.
|
||||
PrimaryIndex int
|
||||
// NextConsensus represents the contract address of the next miner (160 bit BE
|
||||
// value in a 20 byte slice).
|
||||
NextConsensus interop.Hash160
|
||||
|
@ -43,6 +45,7 @@ type BlockSR struct {
|
|||
Timestamp int
|
||||
Nonce int
|
||||
Index int
|
||||
PrimaryIndex int
|
||||
NextConsensus interop.Hash160
|
||||
TransactionsLength int
|
||||
// PrevStateRoot is a hash of the previous block's state root.
|
||||
|
|
Loading…
Reference in a new issue