Skip to content

Commit

Permalink
refactor: postage interface change
Browse files Browse the repository at this point in the history
  • Loading branch information
nugaon committed Sep 25, 2023
1 parent 7a92c17 commit 953633d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 37 deletions.
46 changes: 25 additions & 21 deletions pkg/storageincentives/redistribution/inclusionproof.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,23 @@ type ChunkInclusionProofs struct {
// github.com/ethersphere/storage-incentives/blob/ph_f2/src/Redistribution.sol
// github.com/ethersphere/storage-incentives/blob/master/src/Redistribution.sol (when merged to master)
type ChunkInclusionProof struct {
ProofSegments []string `json:"proofSegments"`
ProveSegment string `json:"proveSegment"`
ProofSegments2 []string `json:"proofSegments2"`
ProveSegment2 string `json:"proveSegment2"`
ChunkSpan uint64 `json:"chunkSpan"`
ProofSegments3 []string `json:"proofSegments3"`
ProofSegments []string `json:"proofSegments"`
ProveSegment string `json:"proveSegment"`
ProofSegments2 []string `json:"proofSegments2"`
ProveSegment2 string `json:"proveSegment2"`
ChunkSpan uint64 `json:"chunkSpan"`
ProofSegments3 []string `json:"proofSegments3"`
PostageProof PostageProof `json:"postageProof"`
SocProof []SOCProof `json:"socProofAttached"`
}

// SOCProof structure must exactly match
// corresponding structure (of the same name) in Redistribution.sol smart contract.
type PostageProof struct {
Signature string `json:"signature"`
ChunkAddr string `json:"chunkAddr"`
PostageId string `json:"postageId"`
Index string `json:"index"`
TimeStamp string `json:"timeStamp"`

SocProofAttached []SOCProof `json:"socProofAttached"`
}

// SOCProof structure must exactly match
Expand All @@ -65,18 +68,19 @@ func NewChunkInclusionProof(proofp1, proofp2 bmt.Proof, proofp3 bmt.Proof, sampl
}

return ChunkInclusionProof{
ProofSegments: proofp1Hex.ProofSegments,
ProveSegment: proofp1Hex.ProveSegment,
ProofSegments2: proofp2Hex.ProofSegments,
ProveSegment2: proofp2Hex.ProveSegment,
ChunkSpan: binary.LittleEndian.Uint64(proofp2.Span[:swarm.SpanSize]), // should be uint64 on the other size; copied from pkg/api/bytes.go
ProofSegments3: proofp3Hex.ProofSegments,
Signature: hex.EncodeToString(sampleItem.Stamp.Sig()),
ChunkAddr: proofp1Hex.ProveSegment, // TODO refactor ABI
PostageId: hex.EncodeToString(sampleItem.Stamp.BatchID()),
Index: hex.EncodeToString(sampleItem.Stamp.Index()),
TimeStamp: hex.EncodeToString(sampleItem.Stamp.Timestamp()),
SocProofAttached: socProof,
ProofSegments: proofp1Hex.ProofSegments,
ProveSegment: proofp1Hex.ProveSegment,
ProofSegments2: proofp2Hex.ProofSegments,
ProveSegment2: proofp2Hex.ProveSegment,
ChunkSpan: binary.LittleEndian.Uint64(proofp2.Span[:swarm.SpanSize]), // should be uint64 on the other size; copied from pkg/api/bytes.go
ProofSegments3: proofp3Hex.ProofSegments,
PostageProof: PostageProof{
Signature: hex.EncodeToString(sampleItem.Stamp.Sig()),
PostageId: hex.EncodeToString(sampleItem.Stamp.BatchID()),
Index: hex.EncodeToString(sampleItem.Stamp.Index()),
TimeStamp: hex.EncodeToString(sampleItem.Stamp.Timestamp()),
},
SocProof: socProof,
}, nil
}

Expand Down
35 changes: 19 additions & 16 deletions pkg/storageincentives/testdata/inclusion-proofs.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@
"b68323ecaad1185a5e078f41c94c59d0b6dda5d57e109866e64d44acb8702846",
"478adfa93a7bb904d0aa86ff0d559f43aa915ee7865592e717b72a24452181cb"
],
"signature": "a7c8d18a8279d3803169ebcf4e5a7dbdd4dffefa591eaad8d1ceaa636a793ad975e7f7b1087bcea4176525b0002edde0acbfda20dbd2dfbbe777cab38968fdc61b",
"chunkAddr": "7133885ac59dca7b97773acb740e978d41a4af45bd563067c8a3d863578488f1",
"postageId": "4c8efc14c8e3cee608174f995d7afe155897bf643a31226e4f1363bc97686aef",
"index": "0000000000080303",
"timeStamp": "0000000000030308",
"postageProof": {
"signature": "a7c8d18a8279d3803169ebcf4e5a7dbdd4dffefa591eaad8d1ceaa636a793ad975e7f7b1087bcea4176525b0002edde0acbfda20dbd2dfbbe777cab38968fdc61b",
"postageId": "4c8efc14c8e3cee608174f995d7afe155897bf643a31226e4f1363bc97686aef",
"index": "0000000000080303",
"timeStamp": "0000000000030308"
},
"socProofAttached": [
{
"signer": "0x827b44d53df2854057713b25cdd653eb70fe36c4",
Expand Down Expand Up @@ -75,11 +76,12 @@
"b68323ecaad1185a5e078f41c94c59d0b6dda5d57e109866e64d44acb8702846",
"478adfa93a7bb904d0aa86ff0d559f43aa915ee7865592e717b72a24452181cb"
],
"signature": "b0274fcda59e8aaffee803021971a764a017ce2c0f41c8ceb6eefdea807056f621a98feab5ebf33bb6065e49c050f413ec8840b008fc224d882ce5244ce3e0171c",
"chunkAddr": "535e6df58a122a8f5e6c851c19b3e042f4cd1b5c5a8c499581c9f6d4e3509182",
"postageId": "4c8efc14c8e3cee608174f995d7afe155897bf643a31226e4f1363bc97686aef",
"index": "0000000000080303",
"timeStamp": "0000000000030308",
"postageProof": {
"signature": "b0274fcda59e8aaffee803021971a764a017ce2c0f41c8ceb6eefdea807056f621a98feab5ebf33bb6065e49c050f413ec8840b008fc224d882ce5244ce3e0171c",
"postageId": "4c8efc14c8e3cee608174f995d7afe155897bf643a31226e4f1363bc97686aef",
"index": "0000000000080303",
"timeStamp": "0000000000030308"
},
"socProofAttached": []
},
"proofLast": {
Expand Down Expand Up @@ -113,11 +115,12 @@
"b68323ecaad1185a5e078f41c94c59d0b6dda5d57e109866e64d44acb8702846",
"478adfa93a7bb904d0aa86ff0d559f43aa915ee7865592e717b72a24452181cb"
],
"signature": "6747c58ce8613486c696f5bb7393c9c59094371969c3a52bfaf75192c605f4ad7c70c6e71fdd320e20d005e42e94ee32102c234eb465f4f5fd9db60fcad0356b1c",
"chunkAddr": "5ba2c8b912fad4aeb4a11a960946d07b9f66bc40ac54d87224914d75f5aeea5f",
"postageId": "4c8efc14c8e3cee608174f995d7afe155897bf643a31226e4f1363bc97686aef",
"index": "0000000000080303",
"timeStamp": "0000000000030308",
"postageProof": {
"signature": "6747c58ce8613486c696f5bb7393c9c59094371969c3a52bfaf75192c605f4ad7c70c6e71fdd320e20d005e42e94ee32102c234eb465f4f5fd9db60fcad0356b1c",
"postageId": "4c8efc14c8e3cee608174f995d7afe155897bf643a31226e4f1363bc97686aef",
"index": "0000000000080303",
"timeStamp": "0000000000030308"
},
"socProofAttached": []
}
}
}

0 comments on commit 953633d

Please sign in to comment.