add logging for darkside rpcs

This commit is contained in:
Larry Ruane 2020-05-20 17:23:39 -06:00 committed by Larry Ruane
parent 007dbbf13c
commit 0217670d8c
1 changed files with 18 additions and 6 deletions

View File

@ -61,6 +61,7 @@ var DarksideEnabled bool
// DarksideInit should be called once at startup in darksidewalletd mode. // DarksideInit should be called once at startup in darksidewalletd mode.
func DarksideInit(c *BlockCache) { func DarksideInit(c *BlockCache) {
Log.Info("Darkside mode running")
DarksideEnabled = true DarksideEnabled = true
state.cache = c state.cache = c
RawRequest = darksideRawRequest RawRequest = darksideRawRequest
@ -73,6 +74,7 @@ func DarksideInit(c *BlockCache) {
// DarksideReset allows the wallet test code to specify values // DarksideReset allows the wallet test code to specify values
// that are returned by GetLightdInfo(). // that are returned by GetLightdInfo().
func DarksideReset(sa int, bi, cn string) error { func DarksideReset(sa int, bi, cn string) error {
Log.Info("Reset(saplingActivation=", sa, ")")
stopIngestor() stopIngestor()
state = darksideState{ state = darksideState{
resetted: true, resetted: true,
@ -108,7 +110,7 @@ func addBlockActive(blockBytes []byte) error {
} }
if blockHeight < state.startHeight { if blockHeight < state.startHeight {
return errors.New(fmt.Sprint("adding block at height ", blockHeight, return errors.New(fmt.Sprint("adding block at height ", blockHeight,
" is lower than Sapling activation height")) " is lower than Sapling activation height ", state.startHeight))
} }
// Drop the block that will be overwritten, and its children, then add block. // Drop the block that will be overwritten, and its children, then add block.
state.activeBlocks = state.activeBlocks[:blockHeight-state.startHeight] state.activeBlocks = state.activeBlocks[:blockHeight-state.startHeight]
@ -133,7 +135,8 @@ func setPrevhash() {
copy(blockBytes[4:4+32], prevhash) copy(blockBytes[4:4+32], prevhash)
} }
prevhash = block.GetEncodableHash() prevhash = block.GetEncodableHash()
Log.Info("height ", block.GetHeight(), " hash ", hex.EncodeToString(block.GetDisplayHash())) Log.Info("height ", block.GetHeight(), " hash ",
hex.EncodeToString(block.GetDisplayHash()))
} }
} }
@ -146,6 +149,7 @@ func DarksideApplyStaged(height int) error {
if !state.resetted { if !state.resetted {
return errors.New("please call Reset first") return errors.New("please call Reset first")
} }
Log.Info("ApplyStaged(height=", height, ")")
// Move the staged blocks into active list // Move the staged blocks into active list
stagedBlocks := state.stagedBlocks stagedBlocks := state.stagedBlocks
state.stagedBlocks = nil state.stagedBlocks = nil
@ -154,11 +158,11 @@ func DarksideApplyStaged(height int) error {
return err return err
} }
} }
if height >= state.startHeight+len(state.activeBlocks) { if height > state.startHeight+len(state.activeBlocks)-1 {
// this is hard to recover from // this is hard to recover from
Log.Fatal("ApplyStaged height ", height, Log.Fatal("ApplyStaged height ", height,
" is greater or equal to highest height ", " is greater than the highest height ",
state.startHeight+len(state.activeBlocks)) state.startHeight+len(state.activeBlocks)-1)
} }
// Add staged transactions into blocks. Note we're not trying to // Add staged transactions into blocks. Note we're not trying to
@ -186,7 +190,7 @@ func DarksideApplyStaged(height int) error {
state.latestHeight = height state.latestHeight = height
Log.Info("active blocks from ", state.startHeight, Log.Info("active blocks from ", state.startHeight,
" to ", state.startHeight+len(state.activeBlocks)-1, " to ", state.startHeight+len(state.activeBlocks)-1,
", latest height ", state.latestHeight) ", latest presented height ", state.latestHeight)
// The block ingestor can only run if there are blocks // The block ingestor can only run if there are blocks
if len(state.activeBlocks) > 0 { if len(state.activeBlocks) > 0 {
@ -209,6 +213,7 @@ func DarksideStageBlocks(url string) error {
if !state.resetted { if !state.resetted {
return errors.New("please call Reset first") return errors.New("please call Reset first")
} }
Log.Info("StageBlocks(url=", url, ")")
resp, err := http.Get(url) resp, err := http.Get(url)
if err != nil { if err != nil {
return err return err
@ -236,6 +241,10 @@ func DarksideStageBlocks(url string) error {
// DarksideStageBlockStream adds the block to the staging area // DarksideStageBlockStream adds the block to the staging area
func DarksideStageBlockStream(blockHex string) error { func DarksideStageBlockStream(blockHex string) error {
if !state.resetted {
return errors.New("please call Reset first")
}
Log.Info("StageBlocks()")
blockBytes, err := hex.DecodeString(blockHex) blockBytes, err := hex.DecodeString(blockHex)
if err != nil { if err != nil {
return err return err
@ -249,6 +258,7 @@ func DarksideStageBlocksCreate(height int32, nonce int32, count int32) error {
if !state.resetted { if !state.resetted {
return errors.New("please call Reset first") return errors.New("please call Reset first")
} }
Log.Info("StageBlocksCreate(height=", height, ", nonce=", nonce, "count=", count, ")")
for i := 0; i < int(count); i++ { for i := 0; i < int(count); i++ {
fakeCoinbase := "0400008085202f890100000000000000000000000000000000000000000000000000" + fakeCoinbase := "0400008085202f890100000000000000000000000000000000000000000000000000" +
@ -419,6 +429,7 @@ func DarksideStageTransaction(height int, txBytes []byte) error {
if !state.resetted { if !state.resetted {
return errors.New("please call Reset first") return errors.New("please call Reset first")
} }
Log.Info("StageTransactions(height=", height, ")")
state.stagedTransactions = append(state.stagedTransactions, state.stagedTransactions = append(state.stagedTransactions,
stagedTx{ stagedTx{
height: height, height: height,
@ -433,6 +444,7 @@ func DarksideStageTransactionsURL(height int, url string) error {
if !state.resetted { if !state.resetted {
return errors.New("please call Reset first") return errors.New("please call Reset first")
} }
Log.Info("StageTransactionsURL(height=", height, "url=", url, ")")
resp, err := http.Get(url) resp, err := http.Get(url)
if err != nil { if err != nil {
return err return err