// queue is full, just ignore.
}
} else {
- fmt.Println("skip sent the block response due to block is nil")
+ bcR.Logger.Info("skip sent the block response due to block is nil")
// TODO peer is asking for things we don't have.
}
case *bcBlockResponseMessage:
// Got a block.
- //fmt.Printf("receive block %v \n", msg.Block)
bcR.pool.AddBlock(src.Key, msg.GetBlock(), len(msgBytes))
case *bcStatusRequestMessage:
// Send peer our state.
}
case *bcStatusResponseMessage:
// Got a peer status. Unverified.
- //fmt.Printf("reveive peer high is %d \n", msg.Height)
bcR.pool.SetPeerHeight(src.Key, msg.Height)
case *bcTransactionMessage:
tx := msg.GetTransaction()
if err := bcR.chain.ValidateTx(tx); err != nil {
- return
+ bcR.Logger.Error("fail to sync transaction to txPool", "err", err)
}
default:
bcR.Logger.Error(cmn.Fmt("Unknown message type %v", reflect.TypeOf(msg)))
import (
"context"
- "fmt"
"encoding/json"
+ "fmt"
"github.com/bytom/errors"
"github.com/bytom/protocol/bc/legacy"
"github.com/bytom/protocol/state"
- dbm "github.com/tendermint/tmlibs/db"
. "github.com/tendermint/tmlibs/common"
+ dbm "github.com/tendermint/tmlibs/db"
)
// A Store encapsulates storage for blockchain validation.
cache blockCache
}
-
//var _ protocol.Store = (*Store)(nil)
func calcBlockHeadKey(height uint64) []byte {
}
func LoadBlock(db dbm.DB, height uint64) *legacy.Block {
- var block *legacy.Block = &legacy.Block{}
- bytez := db.Get(calcBlockKey(height))
- if bytez == nil {
- return nil
- }
-
- fmt.Printf("------LoadBlock height:%v, byte:%v", height, bytez)
- block.UnmarshalText(bytez)
+ var block *legacy.Block = &legacy.Block{}
+ bytez := db.Get(calcBlockKey(height))
+ if bytez == nil {
+ return nil
+ }
+
+ block.UnmarshalText(bytez)
return block
}
return bsj
}
-
// NewStore creates and returns a new Store object.
//
// For testing purposes, it is usually much faster
// instead.
func NewStore(db dbm.DB) *Store {
cache := newBlockCache(func(height uint64) *legacy.Block {
- return LoadBlock(db, height)
- })
+ return LoadBlock(db, height)
+ })
return &Store{
- db: db,
+ db: db,
cache: cache,
- }
+ }
}
// Height returns the height of the blockchain.
func (s *Store) Height() uint64 {
heightJson := LoadBlockStoreStateJSON(s.db)
- return heightJson.Height
+ return heightJson.Height
}
// GetBlock looks up the block with the provided block height.
func (s *Store) GetRawBlock(height uint64) ([]byte, error) {
bytez := s.db.Get(calcBlockKey(height))
if bytez == nil {
- return nil , errors.New("querying blocks from the db null")
+ return nil, errors.New("querying blocks from the db null")
}
return bytez, nil
}
s.cache.add(block)
height := block.Height
- binaryBlock, err := block.MarshalText()
- if err != nil {
- PanicCrisis(Fmt("Error Marshal block meta: %v", err))
- }
+ binaryBlock, err := block.MarshalText()
+ if err != nil {
+ PanicCrisis(Fmt("Error Marshal block meta: %v", err))
+ }
fmt.Printf("------SaveBlock height:%v, byte:%v", height, binaryBlock)
- s.db.Set(calcBlockKey(height), binaryBlock)
+ s.db.Set(calcBlockKey(height), binaryBlock)
// Save new BlockStoreStateJSON descriptor
BlockStoreStateJSON{Height: height}.Save(s.db)
}
func (s *Store) FinalizeBlock(ctx context.Context, height uint64) error {
-// _, err := s.db.ExecContext(ctx, `SELECT pg_notify('newblock', $1)`, height)
+ // _, err := s.db.ExecContext(ctx, `SELECT pg_notify('newblock', $1)`, height)
return nil
}