Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge master -> dev #1558

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from
46 changes: 46 additions & 0 deletions stores/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"go.sia.tech/core/types"
"go.sia.tech/coreutils/chain"
"go.sia.tech/coreutils/wallet"
"go.sia.tech/renterd/api"
"go.sia.tech/renterd/stores/sql"
)
Expand Down Expand Up @@ -208,4 +209,49 @@ func TestProcessChainUpdate(t *testing.T) {
if err := ss.ProcessChainUpdate(context.Background(), func(tx sql.ChainUpdateTx) error { return nil }); err != nil {
panic("oh no")
}

if err := ss.ProcessChainUpdate(context.Background(), func(tx sql.ChainUpdateTx) error {
index3 := types.ChainIndex{Height: 3}
index4 := types.ChainIndex{Height: 4}
created := []types.SiacoinElement{
{
StateElement: types.StateElement{},
SiacoinOutput: types.SiacoinOutput{},
MaturityHeight: 100,
},
}
events := []wallet.Event{
{
Type: wallet.EventTypeV2Transaction,
Data: wallet.EventV2Transaction{},
},
}

// create some elements
err := tx.WalletApplyIndex(index3, created, nil, events, time.Now())
if err != nil {
return err
}

// spend them
err = tx.WalletApplyIndex(index4, nil, created, events, time.Now())
if err != nil {
return err
}

// revert the spend
err = tx.WalletRevertIndex(index4, nil, created, time.Now())
if err != nil {
return err
}

// revert the creation
err = tx.WalletRevertIndex(index3, nil, created, time.Now())
if err != nil {
return err
}
return nil
}); err != nil {
t.Fatal("unexpected error", err)
}
}
2 changes: 1 addition & 1 deletion stores/sql/sqlite/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (c chainUpdateTx) WalletRevertIndex(index types.ChainIndex, removed, unspen
c.l.Debugw(fmt.Sprintf("recreate unspent output %v", e.ID), "height", index.Height, "block_id", index.ID)
if _, err := insertOutputStmt.Exec(c.ctx,
time.Now().UTC(),
e.ID,
ssql.Hash256(e.ID),
e.StateElement.LeafIndex,
ssql.MerkleProof{Hashes: e.StateElement.MerkleProof},
ssql.Currency(e.SiacoinOutput.Value),
Expand Down
Loading