From b9ae3839868204cbd6c96793eb7a03870f7cdf66 Mon Sep 17 00:00:00 2001 From: PJ Date: Thu, 14 Mar 2024 15:01:40 +0100 Subject: [PATCH] stores: pass rev number & filesize from the fce --- internal/test/e2e/cluster_test.go | 22 +++++----------------- stores/subscriber.go | 30 +++++++++++++++++------------- 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/internal/test/e2e/cluster_test.go b/internal/test/e2e/cluster_test.go index 8872dac9c..90d278bf9 100644 --- a/internal/test/e2e/cluster_test.go +++ b/internal/test/e2e/cluster_test.go @@ -595,25 +595,13 @@ func TestUploadDownloadBasic(t *testing.T) { contracts, err := cluster.Bus.Contracts(context.Background(), api.ContractsOpts{}) tt.OK(err) - // assert contracts haven't been revised + // collect the current revision heights + revisionHeights := make(map[types.FileContractID]uint64) for _, c := range contracts { - if c.RevisionHeight != 0 { - t.Fatalf("contract %v 's revision height should be 0 but is %d", c.ID, c.RevisionHeight) - } + revisionHeights[c.ID] = c.RevisionHeight } - // broadcast the revision for each contract, we empty the pool first to - // ensure the revision aren't mined together with contract formations, this - // would not be considered a revision and the revision height would not be - // updated. - tt.Retry(10, 100*time.Millisecond, func() error { - txns := cluster.cm.PoolTransactions() - if len(txns) > 0 { - cluster.MineBlocks(1) - return errors.New("pool not empty") - } - return nil - }) + // broadcast the revision for each contract for _, c := range contracts { tt.OK(w.RHPBroadcast(context.Background(), c.ID)) } @@ -628,7 +616,7 @@ func TestUploadDownloadBasic(t *testing.T) { } // assert the revision height was updated. for _, c := range contracts { - if c.RevisionHeight == 0 { + if c.RevisionHeight == revisionHeights[c.ID] { return fmt.Errorf("%v should have been revised", c.ID) } } diff --git a/stores/subscriber.go b/stores/subscriber.go index 8846f359e..63e812928 100644 --- a/stores/subscriber.go +++ b/stores/subscriber.go @@ -371,28 +371,30 @@ func (cs *chainSubscriber) processChainApplyUpdateContracts(cau *chain.ApplyUpda // v1 contracts cau.ForEachFileContractElement(func(fce types.FileContractElement, rev *types.FileContractElement, resolved, valid bool) { - var r *revision + r := &revision{ + revisionNumber: fce.FileContract.RevisionNumber, + fileSize: fce.FileContract.Filesize, + } if rev != nil { - r = &revision{ - revisionNumber: rev.FileContract.RevisionNumber, - fileSize: rev.FileContract.Filesize, - } + r.revisionNumber = rev.FileContract.RevisionNumber + r.fileSize = rev.FileContract.Filesize } processContract(fce.ID, r, resolved, valid) }) // v2 contracts cau.ForEachV2FileContractElement(func(fce types.V2FileContractElement, rev *types.V2FileContractElement, res types.V2FileContractResolutionType) { - var r *revision - if rev != nil { - r = &revision{ - revisionNumber: rev.V2FileContract.RevisionNumber, - fileSize: rev.V2FileContract.Filesize, - } + r := &revision{ + revisionNumber: fce.V2FileContract.RevisionNumber, + fileSize: fce.V2FileContract.Filesize, } - resolved := res != nil - valid := false + + var valid bool + var resolved bool if res != nil { + r.revisionNumber = rev.V2FileContract.RevisionNumber + r.fileSize = rev.V2FileContract.Filesize + switch res.(type) { case *types.V2FileContractFinalization: valid = true @@ -403,6 +405,8 @@ func (cs *chainSubscriber) processChainApplyUpdateContracts(cau *chain.ApplyUpda case *types.V2FileContractExpiration: valid = fce.V2FileContract.Filesize == 0 } + + resolved = true } processContract(fce.ID, r, resolved, valid) })