Skip to content

Commit

Permalink
Merge branch 'multiproofs'
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechampine committed Oct 10, 2023
2 parents 1ffcbe7 + b119d5e commit a072abe
Show file tree
Hide file tree
Showing 5 changed files with 438 additions and 103 deletions.
86 changes: 0 additions & 86 deletions consensus/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,89 +191,3 @@ func TestApplyBlock(t *testing.T) {
checkUpdateElements(au, addedSCEs, spentSCEs, addedSFEs, spentSFEs)
}
}

/*
func TestApplyV2Block(t *testing.T) {
n, genesisBlock := chain.TestnetZen()
n.InitialTarget = types.BlockID{0xFF}
n.HardforkDevAddr.Height = 0
n.HardforkTax.Height = 0
n.HardforkStorageProof.Height = 0
n.HardforkOak.Height = 0
n.HardforkASIC.Height = 0
n.HardforkFoundation.Height = 0
n.HardforkV2.AllowHeight = 1
n.HardforkV2.RequireHeight = 1
cs := n.GenesisState()
bs := consensus.V1BlockSupplement{Transactions: make([]consensus.V1TransactionSupplement, len(genesisBlock.Transactions))}
cs, cau := consensus.ApplyBlock(cs, genesisBlock, bs, time.Time{})
var sces []types.SiacoinElement
cau.ForEachSiacoinElement(func(sce types.SiacoinElement, spent bool) { sces = append(sces, sce) })
for i := range sces {
if !cs.Elements.ContainsUnspentSiacoinElement(sces[i]) {
t.Fatal("missing siacoin element")
}
}
b := types.Block{
ParentID: cs.Index.ID,
Timestamp: types.CurrentTimestamp(),
MinerPayouts: []types.SiacoinOutput{{Address: types.VoidAddress, Value: cs.BlockReward()}},
}
cs, cau = consensus.ApplyBlock(cs, b, consensus.V1BlockSupplement{}, time.Time{})
for i := range sces {
cau.UpdateElementProof(&sces[i].StateElement)
}
b = types.Block{
ParentID: cs.Index.ID,
Timestamp: types.CurrentTimestamp(),
MinerPayouts: []types.SiacoinOutput{{Address: types.VoidAddress, Value: cs.BlockReward()}},
V2: &types.V2BlockData{
Transactions: []types.V2Transaction{{
SiacoinInputs: []types.V2SiacoinInput{{Parent: sces[1]}},
MinerFee: sces[1].SiacoinOutput.Value,
}},
},
}
b.V2.Transactions[0].SiacoinOutputs = append(b.V2.Transactions[0].SiacoinOutputs, make([]types.SiacoinOutput, 30)...)
cs, cau = consensus.ApplyBlock(cs, b, consensus.V1BlockSupplement{}, time.Time{})
for i := range sces {
cau.UpdateElementProof(&sces[i].StateElement)
cau.UpdateElementProof(&sces[i].StateElement)
cau.UpdateElementProof(&sces[i].StateElement)
}
if !cs.Elements.ContainsUnspentSiacoinElement(sces[0]) {
t.Error("missing siacoin element", 0)
}
if !cs.Elements.ContainsSpentSiacoinElement(sces[1]) {
t.Error("missing siacoin element", 1)
}
b = types.Block{
ParentID: cs.Index.ID,
Timestamp: types.CurrentTimestamp(),
MinerPayouts: []types.SiacoinOutput{{Address: types.VoidAddress, Value: cs.BlockReward()}},
V2: &types.V2BlockData{
Transactions: []types.V2Transaction{{
SiacoinInputs: []types.V2SiacoinInput{{Parent: sces[0]}},
MinerFee: sces[0].SiacoinOutput.Value,
}},
},
}
b.V2.Transactions[0].SiacoinOutputs = append(b.V2.Transactions[0].SiacoinOutputs, make([]types.SiacoinOutput, 30)...)
cs, cau = consensus.ApplyBlock(cs, b, consensus.V1BlockSupplement{}, time.Time{})
for i := range sces {
cau.UpdateElementProof(&sces[i].StateElement)
cau.UpdateElementProof(&sces[i].StateElement)
cau.UpdateElementProof(&sces[i].StateElement)
}
if !cs.Elements.ContainsSpentSiacoinElement(sces[0]) {
t.Error("missing siacoin element", 0)
}
if !cs.Elements.ContainsSpentSiacoinElement(sces[1]) {
t.Error("missing siacoin element", 1)
}
}
*/
17 changes: 8 additions & 9 deletions consensus/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,13 +475,12 @@ func TestValidateV2Block(t *testing.T) {
Filesize: v1GiftFC.Filesize,
ProofHeight: 5,
ExpirationHeight: 10,
// ExpirationHeight:
RenterOutput: v1GiftFC.ValidProofOutputs[0],
HostOutput: v1GiftFC.ValidProofOutputs[1],
MissedHostValue: v1GiftFC.MissedProofOutputs[1].Value,
TotalCollateral: v1GiftFC.Payout,
RenterPublicKey: renterPublicKey,
HostPublicKey: hostPublicKey,
RenterOutput: v1GiftFC.ValidProofOutputs[0],
HostOutput: v1GiftFC.ValidProofOutputs[1],
MissedHostValue: v1GiftFC.MissedProofOutputs[1].Value,
TotalCollateral: v1GiftFC.Payout,
RenterPublicKey: renterPublicKey,
HostPublicKey: hostPublicKey,
}

giftTxn := types.V2Transaction{
Expand Down Expand Up @@ -523,7 +522,7 @@ func TestValidateV2Block(t *testing.T) {

fc := v2GiftFC
fc.TotalCollateral = fc.HostOutput.Value
difference, _ := types.ParseCurrency("2080000000000000000000000")
contractCost := fc.RenterOutput.Value.Add(fc.HostOutput.Value).Add(cs.V2FileContractTax(fc))

rev1 := v2GiftFC
rev1.RevisionNumber++
Expand All @@ -544,7 +543,7 @@ func TestValidateV2Block(t *testing.T) {
SatisfiedPolicy: types.SatisfiedPolicy{Policy: giftPolicy},
}},
SiacoinOutputs: []types.SiacoinOutput{
{Value: giftAmountSC.Sub(minerFee).Sub(difference), Address: giftAddress},
{Value: giftAmountSC.Sub(minerFee).Sub(contractCost), Address: giftAddress},
},
SiafundOutputs: []types.SiafundOutput{
{Value: giftAmountSF / 2, Address: giftAddress},
Expand Down
10 changes: 2 additions & 8 deletions types/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,10 +725,7 @@ func (txn V2Transaction) EncodeTo(e *Encoder) {
func (b V2BlockData) EncodeTo(e *Encoder) {
e.WriteUint64(b.Height)
b.Commitment.EncodeTo(e)
e.WritePrefix(len(b.Transactions))
for i := range b.Transactions {
b.Transactions[i].EncodeTo(e)
}
V2TransactionsMultiproof(b.Transactions).EncodeTo(e)
}

// V1Block provides v1 encoding for Block.
Expand Down Expand Up @@ -1288,10 +1285,7 @@ func (txn *V2Transaction) DecodeFrom(d *Decoder) {
func (b *V2BlockData) DecodeFrom(d *Decoder) {
b.Height = d.ReadUint64()
b.Commitment.DecodeFrom(d)
b.Transactions = make([]V2Transaction, d.ReadPrefix())
for i := range b.Transactions {
b.Transactions[i].DecodeFrom(d)
}
(*V2TransactionsMultiproof)(&b.Transactions).DecodeFrom(d)
}

// DecodeFrom implements types.DecoderFrom.
Expand Down
Loading

0 comments on commit a072abe

Please sign in to comment.