Skip to content

Commit

Permalink
stores: pass rev number & filesize from the fce
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjan committed Mar 14, 2024
1 parent 80d98b9 commit b9ae383
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 30 deletions.
22 changes: 5 additions & 17 deletions internal/test/e2e/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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)
}
}
Expand Down
30 changes: 17 additions & 13 deletions stores/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
})
Expand Down

0 comments on commit b9ae383

Please sign in to comment.