Skip to content

Commit

Permalink
add block sanitize function for comparisons (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
fschoell authored Jan 3, 2024
1 parent 4309f0d commit a102c71
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/fireantelope/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func Chain() *firecore.Chain[*pbantelope.Block] {
return nil
},

SanitizeBlockForCompare: sanitizeBlockForCompare,

//TransformFlags: map[string]*firecore.TransformFlag{
// "receipt-account-filters": {
// Description: "Comma-separated accounts to use as filter/index. If it contains a colon (:), it will be interpreted as <prefix>:<suffix> (each of which can be empty, ex: 'hello:' or ':world')",
Expand Down
74 changes: 74 additions & 0 deletions cmd/fireantelope/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package main

import (
"fmt"
pbantelope "github.com/pinax-network/firehose-antelope/types/pb/sf/antelope/type/v1"
"google.golang.org/protobuf/types/known/timestamppb"
"strconv"
"time"
)

func mustParseUint64(in string) uint64 {
Expand All @@ -13,3 +16,74 @@ func mustParseUint64(in string) uint64 {

return out
}

func sanitizeBlockForCompare(block *pbantelope.Block) *pbantelope.Block {

fixedTimestamp := timestamppb.New(time.Now())

var sanitizeContext func(logContext *pbantelope.Exception_LogContext)
sanitizeContext = func(logContext *pbantelope.Exception_LogContext) {
if logContext != nil {
logContext.Line = 0
logContext.ThreadName = "thread"
logContext.Timestamp = fixedTimestamp
sanitizeContext(logContext.Context)
}
}

sanitizeException := func(exception *pbantelope.Exception) {
if exception != nil {
for _, stack := range exception.Stack {
sanitizeContext(stack.Context)
}
}
}

sanitizeRLimitOp := func(rlimitOp *pbantelope.RlimitOp) {
switch v := rlimitOp.Kind.(type) {
case *pbantelope.RlimitOp_AccountUsage:
v.AccountUsage.CpuUsage.LastOrdinal = 111
v.AccountUsage.NetUsage.LastOrdinal = 222
case *pbantelope.RlimitOp_State:
v.State.AverageBlockCpuUsage.LastOrdinal = 333
v.State.AverageBlockNetUsage.LastOrdinal = 444
}
}

for _, rlimitOp := range block.RlimitOps {
sanitizeRLimitOp(rlimitOp)
}

for _, trxTrace := range block.UnfilteredTransactionTraces {
trxTrace.Elapsed = 888
sanitizeException(trxTrace.Exception)

for _, permOp := range trxTrace.PermOps {
if permOp.OldPerm != nil {
permOp.OldPerm.LastUpdated = fixedTimestamp
}

if permOp.NewPerm != nil {
permOp.NewPerm.LastUpdated = fixedTimestamp
}
}

for _, rlimitOp := range trxTrace.RlimitOps {
sanitizeRLimitOp(rlimitOp)
}

for _, actTrace := range trxTrace.ActionTraces {
actTrace.Elapsed = 999
sanitizeException(actTrace.Exception)
}

if trxTrace.FailedDtrxTrace != nil {
sanitizeException(trxTrace.FailedDtrxTrace.Exception)
for _, actTrace := range trxTrace.FailedDtrxTrace.ActionTraces {
sanitizeException(actTrace.Exception)
}
}
}

return block
}

0 comments on commit a102c71

Please sign in to comment.