2021-02-08 08:10:25 +00:00
|
|
|
package ledger
|
|
|
|
|
|
|
|
import "github.com/nspcc-dev/neo-go/pkg/interop"
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// Block represents a NEO block, it's a data structure where you can get
|
2021-02-08 08:10:25 +00:00
|
|
|
// block-related data from. It's similar to the Block class in the Neo .net
|
2022-04-20 18:30:09 +00:00
|
|
|
// framework. To use it, you need to get it via GetBlock function call.
|
2021-02-08 08:10:25 +00:00
|
|
|
type Block struct {
|
|
|
|
// Hash represents the hash (256 bit BE value in a 32 byte slice) of the
|
|
|
|
// given block.
|
|
|
|
Hash interop.Hash256
|
|
|
|
// Version of the block.
|
|
|
|
Version int
|
|
|
|
// PrevHash represents the hash (256 bit BE value in a 32 byte slice) of the
|
|
|
|
// previous block.
|
|
|
|
PrevHash interop.Hash256
|
|
|
|
// MerkleRoot represents the root hash (256 bit BE value in a 32 byte slice)
|
|
|
|
// of a transaction list.
|
|
|
|
MerkleRoot interop.Hash256
|
|
|
|
// Timestamp represents millisecond-precision block timestamp.
|
|
|
|
Timestamp int
|
2021-07-14 08:32:54 +00:00
|
|
|
// Nonce represents block nonce.
|
|
|
|
Nonce int
|
2021-02-08 08:10:25 +00:00
|
|
|
// Index represents the height of the block.
|
|
|
|
Index int
|
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 when ac527650eb173bb1dbd799d44fea7309fce42ad3 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 when 3a4e0caeb8c019fcaaff50090286f5aef634d345 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>
2024-07-27 09:28:30 +00:00
|
|
|
// PrimaryIndex represents the index of the primary node that created this block.
|
|
|
|
PrimaryIndex int
|
2022-04-20 18:30:09 +00:00
|
|
|
// NextConsensus represents the contract address of the next miner (160 bit BE
|
2021-02-08 08:10:25 +00:00
|
|
|
// value in a 20 byte slice).
|
|
|
|
NextConsensus interop.Hash160
|
|
|
|
// TransactionsLength represents the length of block's transactions array.
|
|
|
|
TransactionsLength int
|
|
|
|
}
|
2022-07-06 08:52:06 +00:00
|
|
|
|
|
|
|
// BlockSR is a stateroot-enabled Neo block. It's returned from the Ledger contract's
|
|
|
|
// GetBlock method when StateRootInHeader NeoGo extension is used. Use it only when
|
|
|
|
// you have it enabled when you need to access PrevStateRoot field, Block is sufficient
|
|
|
|
// otherwise. To get this data type ToBlockSR method of Block should be used. All of
|
|
|
|
// the fields are same as in Block except PrevStateRoot.
|
|
|
|
type BlockSR struct {
|
|
|
|
Hash interop.Hash256
|
|
|
|
Version int
|
|
|
|
PrevHash interop.Hash256
|
|
|
|
MerkleRoot interop.Hash256
|
|
|
|
Timestamp int
|
|
|
|
Nonce int
|
|
|
|
Index int
|
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 when ac527650eb173bb1dbd799d44fea7309fce42ad3 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 when 3a4e0caeb8c019fcaaff50090286f5aef634d345 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>
2024-07-27 09:28:30 +00:00
|
|
|
PrimaryIndex int
|
2022-07-06 08:52:06 +00:00
|
|
|
NextConsensus interop.Hash160
|
|
|
|
TransactionsLength int
|
|
|
|
// PrevStateRoot is a hash of the previous block's state root.
|
|
|
|
PrevStateRoot interop.Hash256
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToBlockSR converts Block into BlockSR for chains with StateRootInHeader option.
|
|
|
|
func (b *Block) ToBlockSR() *BlockSR {
|
2023-04-03 10:34:24 +00:00
|
|
|
return any(b).(*BlockSR)
|
2022-07-06 08:52:06 +00:00
|
|
|
}
|