update submitblocks.sh, return an error if GetBlock height is too low, instead of crashing

This commit is contained in:
Larry Ruane 2020-05-18 17:33:27 -06:00 committed by Larry Ruane
parent 39348100a9
commit f8794dbe05
2 changed files with 13 additions and 4 deletions

View File

@ -143,7 +143,9 @@ func DarksideApplyStaged(height int) error {
return errors.New("please call Reset first")
}
// Move the staged blocks into active list
for _, blockBytes := range state.stagedBlocks {
stagedBlocks := state.stagedBlocks
state.stagedBlocks = nil
for _, blockBytes := range stagedBlocks {
if err := addBlockActive(blockBytes); err != nil {
return err
}
@ -329,6 +331,10 @@ func darksideRawRequest(method string, params []json.RawMessage) (json.RawMessag
if height > state.latestHeight {
return nil, errors.New(notFoundErr)
}
if height < state.startHeight {
return nil, errors.New(fmt.Sprint("getblock: requesting height ", height,
" is less than sapling activation height"))
}
index := height - state.startHeight
return []byte("\"" + hex.EncodeToString(state.activeBlocks[index]) + "\""), nil

View File

@ -6,8 +6,11 @@
set -e
test $# -ne 2 && { echo usage: $0 sapling-height blocks-file;exit 1;}
JSON="{\"saplingActivation\": $1, \"branchID\": \"2bb40e60\", \"chainName\": \"main\"}"
grpcurl -plaintext -d "$JSON" localhost:9067 cash.z.wallet.sdk.rpc.DarksideStreamer/SetMetaState
# must do a Reset first
grpcurl -plaintext -d '{"saplingActivation":'$1',"branchID":"2bb40e60","chainName":"main"}' localhost:9067 cash.z.wallet.sdk.rpc.DarksideStreamer/Reset
# send the blocks and make them active
sed 's/^/{"block":"/;s/$/"}/' $2 |
grpcurl -plaintext -d @ localhost:9067 cash.z.wallet.sdk.rpc.DarksideStreamer/SetBlocks
grpcurl -plaintext -d @ localhost:9067 cash.z.wallet.sdk.rpc.DarksideStreamer/StageBlocksStream
let latest=$1+$(cat $2|wc -l)-1
grpcurl -plaintext -d '{"height":'$latest'}' localhost:9067 cash.z.wallet.sdk.rpc.DarksideStreamer/ApplyStaged