github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/forensics/capture.go (about)

     1  package forensics
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/hyperledger/burrow/binary"
     7  	"github.com/hyperledger/burrow/execution/exec"
     8  	"github.com/pkg/errors"
     9  )
    10  
    11  type ReplayCapture struct {
    12  	Height        uint64
    13  	AppHashBefore binary.HexBytes
    14  	AppHashAfter  binary.HexBytes
    15  	TxExecutions  []*exec.TxExecution
    16  }
    17  
    18  func (rc *ReplayCapture) String() string {
    19  	return fmt.Sprintf("ReplayCapture[Height %d; AppHash: %v -> %v]",
    20  		rc.Height, rc.AppHashBefore, rc.AppHashAfter)
    21  }
    22  
    23  // Compare the app hashes of two block replays
    24  func (exp *ReplayCapture) Compare(act *ReplayCapture) error {
    25  	if exp.AppHashBefore.String() != act.AppHashBefore.String() {
    26  		return fmt.Errorf("app hashes before do not match")
    27  	} else if exp.AppHashAfter.String() != act.AppHashAfter.String() {
    28  		return fmt.Errorf("app hashes after do not match")
    29  	}
    30  
    31  	return nil
    32  }
    33  
    34  // CompareCaptures of two independent replays
    35  func CompareCaptures(exp, act []*ReplayCapture) (uint64, error) {
    36  	for i, rc := range exp {
    37  		if err := rc.Compare(act[i]); err != nil {
    38  			return rc.Height, errors.Wrapf(err, "mismatch at height %d", rc.Height)
    39  		}
    40  	}
    41  	return 0, nil
    42  }