core: remove (*block.Block) checks for topBlock

If it's non-nil, it has *block.Block inside. If it doesn't --- tell everyone
about it with a nice panic message.
This commit is contained in:
Roman Khimov 2020-09-16 17:40:27 +03:00
parent 33ea179f6e
commit 6bffa811d4

View file

@ -901,7 +901,8 @@ func (bc *Blockchain) GetStorageItems(id int32) (map[string]*state.StorageItem,
func (bc *Blockchain) GetBlock(hash util.Uint256) (*block.Block, error) {
topBlock := bc.topBlock.Load()
if topBlock != nil {
if tb, ok := topBlock.(*block.Block); ok && tb.Hash().Equals(hash) {
tb := topBlock.(*block.Block)
if tb.Hash().Equals(hash) {
return tb, nil
}
}
@ -924,7 +925,8 @@ func (bc *Blockchain) GetBlock(hash util.Uint256) (*block.Block, error) {
func (bc *Blockchain) GetHeader(hash util.Uint256) (*block.Header, error) {
topBlock := bc.topBlock.Load()
if topBlock != nil {
if tb, ok := topBlock.(*block.Block); ok && tb.Hash().Equals(hash) {
tb := topBlock.(*block.Block)
if tb.Hash().Equals(hash) {
return tb.Header(), nil
}
}
@ -954,10 +956,9 @@ func (bc *Blockchain) HasBlock(hash util.Uint256) bool {
func (bc *Blockchain) CurrentBlockHash() util.Uint256 {
topBlock := bc.topBlock.Load()
if topBlock != nil {
if tb, ok := topBlock.(*block.Block); ok {
tb := topBlock.(*block.Block)
return tb.Hash()
}
}
return bc.GetHeaderHash(int(bc.BlockHeight()))
}