Skip to content

Commit

Permalink
feat: reduce unnecessary proof calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bisonai committed Aug 5, 2024
1 parent 299719c commit 0048099
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions node/pkg/dal/collector/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,13 @@ func subscribeAddOracleEvent(ctx context.Context, chainReader *websocketchainrea
}

func orderProof(ctx context.Context, proof []byte, value int64, timestamp time.Time, symbol string, cachedWhitelist []klaytncommon.Address) ([]byte, error) {
proof, err := removeDuplicateProof(proof)
proofChunks, err := getUniqueProofChunks(proof)
if err != nil {
log.Error().Err(err).Msg("failed to remove duplicate proofs in orderProof")
return nil, err
}

hash := chainutils.Value2HashForSign(value, timestamp.UnixMilli(), symbol)
proofChunks, err := splitProofToChunk(proof)
if err != nil {
log.Error().Err(err).Msg("failed to split proof to chunks in orderProof")
return nil, err
}

log.Debug().Int("len", len(proofChunks)).Any("chunks", proofChunks).Msg("proof chunks")

signers, err := getSignerListFromProofs(hash, proofChunks)
Expand All @@ -117,7 +111,7 @@ func orderProof(ctx context.Context, proof []byte, value int64, timestamp time.T
return validateProof(signerMap, cachedWhitelist)
}

func removeDuplicateProof(proof []byte) ([]byte, error) {
func getUniqueProofChunks(proof []byte) ([][]byte, error) {
proofs, err := splitProofToChunk(proof)
if err != nil {
return nil, err
Expand All @@ -133,7 +127,7 @@ func removeDuplicateProof(proof []byte) ([]byte, error) {
result = append(result, p)
}

return bytes.Join(result, nil), nil
return result, nil
}

func splitProofToChunk(proof []byte) ([][]byte, error) {
Expand Down

0 comments on commit 0048099

Please sign in to comment.