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

Update core #115

Merged
merged 4 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions chain/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

type memState struct {
index types.ChainIndex
utxos map[types.Hash256]types.SiacoinElement
utxos map[types.SiacoinOutputID]types.SiacoinElement
chainIndexElements []types.ChainIndexElement
}

Expand Down Expand Up @@ -109,7 +109,7 @@ func (ms *memState) SpendableElement(t *testing.T) (se types.SiacoinElement) {

func newMemState() *memState {
return &memState{
utxos: make(map[types.Hash256]types.SiacoinElement),
utxos: make(map[types.SiacoinOutputID]types.SiacoinElement),
}
}

Expand Down
12 changes: 6 additions & 6 deletions chain/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,13 @@ func (db *DBStore) getElementProof(leafIndex, numLeaves uint64) (proof []types.H
func (db *DBStore) getSiacoinElement(id types.SiacoinOutputID, numLeaves uint64) (sce types.SiacoinElement, ok bool) {
ok = db.bucket(bSiacoinElements).get(id[:], &sce)
if ok {
sce.MerkleProof = db.getElementProof(sce.LeafIndex, numLeaves)
sce.StateElement.MerkleProof = db.getElementProof(sce.StateElement.LeafIndex, numLeaves)
}
return
}

func (db *DBStore) putSiacoinElement(sce types.SiacoinElement) {
sce.MerkleProof = nil
sce.StateElement.MerkleProof = nil
db.bucket(bSiacoinElements).put(sce.ID[:], sce)
}

Expand All @@ -369,13 +369,13 @@ func (db *DBStore) deleteSiacoinElement(id types.SiacoinOutputID) {
func (db *DBStore) getSiafundElement(id types.SiafundOutputID, numLeaves uint64) (sfe types.SiafundElement, ok bool) {
ok = db.bucket(bSiafundElements).get(id[:], &sfe)
if ok {
sfe.MerkleProof = db.getElementProof(sfe.LeafIndex, numLeaves)
sfe.StateElement.MerkleProof = db.getElementProof(sfe.StateElement.LeafIndex, numLeaves)
}
return
}

func (db *DBStore) putSiafundElement(sfe types.SiafundElement) {
sfe.MerkleProof = nil
sfe.StateElement.MerkleProof = nil
db.bucket(bSiafundElements).put(sfe.ID[:], sfe)
}

Expand All @@ -386,13 +386,13 @@ func (db *DBStore) deleteSiafundElement(id types.SiafundOutputID) {
func (db *DBStore) getFileContractElement(id types.FileContractID, numLeaves uint64) (fce types.FileContractElement, ok bool) {
ok = db.bucket(bFileContractElements).get(id[:], &fce)
if ok {
fce.MerkleProof = db.getElementProof(fce.LeafIndex, numLeaves)
fce.StateElement.MerkleProof = db.getElementProof(fce.StateElement.LeafIndex, numLeaves)
}
return
}

func (db *DBStore) putFileContractElement(fce types.FileContractElement) {
fce.MerkleProof = nil
fce.StateElement.MerkleProof = nil
db.bucket(bFileContractElements).put(fce.ID[:], fce)
}

Expand Down
66 changes: 33 additions & 33 deletions chain/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,48 +667,48 @@ func (m *Manager) revertPoolUpdate(cru consensus.RevertUpdate, cs consensus.Stat
// applying a block can make ephemeral elements in the txpool non-ephemeral;
// here, we undo that
var uncreated map[types.Hash256]bool
replaceEphemeral := func(e *types.StateElement) {
replaceEphemeral := func(id types.Hash256, e *types.StateElement) {
if e.LeafIndex == types.UnassignedLeafIndex {
return
} else if uncreated == nil {
uncreated = make(map[types.Hash256]bool)
cru.ForEachSiacoinElement(func(sce types.SiacoinElement, created, spent bool) {
if created {
uncreated[sce.ID] = true
uncreated[types.Hash256(sce.ID)] = true
}
})
cru.ForEachSiafundElement(func(sfe types.SiafundElement, created, spent bool) {
if created {
uncreated[sfe.ID] = true
uncreated[types.Hash256(sfe.ID)] = true
}
})
cru.ForEachFileContractElement(func(fce types.FileContractElement, created bool, rev *types.FileContractElement, resolved, valid bool) {
if created {
uncreated[fce.ID] = true
uncreated[types.Hash256(fce.ID)] = true
}
})
cru.ForEachV2FileContractElement(func(fce types.V2FileContractElement, created bool, rev *types.V2FileContractElement, res types.V2FileContractResolutionType) {
if created {
uncreated[fce.ID] = true
uncreated[types.Hash256(fce.ID)] = true
}
})
}
if uncreated[e.ID] {
*e = types.StateElement{ID: e.ID, LeafIndex: types.UnassignedLeafIndex}
if uncreated[id] {
*e = types.StateElement{LeafIndex: types.UnassignedLeafIndex}
}
}
for _, txn := range m.txpool.v2txns {
for i := range txn.SiacoinInputs {
replaceEphemeral(&txn.SiacoinInputs[i].Parent.StateElement)
for i, si := range txn.SiacoinInputs {
replaceEphemeral(types.Hash256(si.Parent.ID), &txn.SiacoinInputs[i].Parent.StateElement)
}
for i := range txn.SiafundInputs {
replaceEphemeral(&txn.SiafundInputs[i].Parent.StateElement)
for i, si := range txn.SiafundInputs {
replaceEphemeral(types.Hash256(si.Parent.ID), &txn.SiafundInputs[i].Parent.StateElement)
}
for i := range txn.FileContractRevisions {
replaceEphemeral(&txn.FileContractRevisions[i].Parent.StateElement)
for i, fcr := range txn.FileContractRevisions {
replaceEphemeral(types.Hash256(fcr.Parent.ID), &txn.FileContractRevisions[i].Parent.StateElement)
}
for i := range txn.FileContractResolutions {
replaceEphemeral(&txn.FileContractResolutions[i].Parent.StateElement)
for i, fcr := range txn.FileContractResolutions {
replaceEphemeral(types.Hash256(fcr.Parent.ID), &txn.FileContractResolutions[i].Parent.StateElement)
}
}

Expand All @@ -724,48 +724,48 @@ func (m *Manager) revertPoolUpdate(cru consensus.RevertUpdate, cs consensus.Stat
func (m *Manager) applyPoolUpdate(cau consensus.ApplyUpdate, cs consensus.State) {
// applying a block can make ephemeral elements in the txpool non-ephemeral
var newElements map[types.Hash256]types.StateElement
replaceEphemeral := func(e *types.StateElement) {
replaceEphemeral := func(id types.Hash256, e *types.StateElement) {
if e.LeafIndex != types.UnassignedLeafIndex {
return
} else if newElements == nil {
newElements = make(map[types.Hash256]types.StateElement)
cau.ForEachSiacoinElement(func(sce types.SiacoinElement, created, spent bool) {
if created {
newElements[sce.ID] = sce.StateElement
newElements[types.Hash256(sce.ID)] = sce.StateElement
}
})
cau.ForEachSiafundElement(func(sfe types.SiafundElement, created, spent bool) {
if created {
newElements[sfe.ID] = sfe.StateElement
newElements[types.Hash256(sfe.ID)] = sfe.StateElement
}
})
cau.ForEachFileContractElement(func(fce types.FileContractElement, created bool, rev *types.FileContractElement, resolved, valid bool) {
if created {
newElements[fce.ID] = fce.StateElement
newElements[types.Hash256(fce.ID)] = fce.StateElement
}
})
cau.ForEachV2FileContractElement(func(fce types.V2FileContractElement, created bool, rev *types.V2FileContractElement, res types.V2FileContractResolutionType) {
if created {
newElements[fce.ID] = fce.StateElement
newElements[types.Hash256(fce.ID)] = fce.StateElement
}
})
}
if se, ok := newElements[e.ID]; ok {
if se, ok := newElements[id]; ok {
*e = se
}
}
for _, txn := range m.txpool.v2txns {
for i := range txn.SiacoinInputs {
replaceEphemeral(&txn.SiacoinInputs[i].Parent.StateElement)
for i, si := range txn.SiacoinInputs {
replaceEphemeral(types.Hash256(si.Parent.ID), &txn.SiacoinInputs[i].Parent.StateElement)
}
for i := range txn.SiafundInputs {
replaceEphemeral(&txn.SiafundInputs[i].Parent.StateElement)
for i, si := range txn.SiafundInputs {
replaceEphemeral(types.Hash256(si.Parent.ID), &txn.SiafundInputs[i].Parent.StateElement)
}
for i := range txn.FileContractRevisions {
replaceEphemeral(&txn.FileContractRevisions[i].Parent.StateElement)
for i, fcr := range txn.FileContractRevisions {
replaceEphemeral(types.Hash256(fcr.Parent.ID), &txn.FileContractRevisions[i].Parent.StateElement)
}
for i := range txn.FileContractResolutions {
replaceEphemeral(&txn.FileContractResolutions[i].Parent.StateElement)
for i, fcr := range txn.FileContractResolutions {
replaceEphemeral(types.Hash256(fcr.Parent.ID), &txn.FileContractResolutions[i].Parent.StateElement)
}
}

Expand Down Expand Up @@ -1082,12 +1082,12 @@ func (m *Manager) updateV2TransactionProofs(txns []types.V2Transaction, from, to
confirmedStateElements := make(map[types.Hash256]types.StateElement)
cau.ForEachSiacoinElement(func(sce types.SiacoinElement, created, spent bool) {
if created {
confirmedStateElements[sce.ID] = sce.StateElement
confirmedStateElements[types.Hash256(sce.ID)] = sce.StateElement
}
})
cau.ForEachSiafundElement(func(sfe types.SiafundElement, created, spent bool) {
if created {
confirmedStateElements[sfe.ID] = sfe.StateElement
confirmedStateElements[types.Hash256(sfe.ID)] = sfe.StateElement
}
})

Expand All @@ -1100,7 +1100,7 @@ func (m *Manager) updateV2TransactionProofs(txns []types.V2Transaction, from, to

// update the state elements for any confirmed ephemeral elements
for j := range txns[i].SiacoinInputs {
if txns[i].SiacoinInputs[j].Parent.LeafIndex != types.UnassignedLeafIndex {
if txns[i].SiacoinInputs[j].Parent.StateElement.LeafIndex != types.UnassignedLeafIndex {
continue
}
se, ok := confirmedStateElements[types.Hash256(txns[i].SiacoinInputs[j].Parent.ID)]
Expand All @@ -1112,7 +1112,7 @@ func (m *Manager) updateV2TransactionProofs(txns []types.V2Transaction, from, to

// update the state elements for any confirmed ephemeral elements
for j := range txns[i].SiafundInputs {
if txns[i].SiafundInputs[j].Parent.LeafIndex != types.UnassignedLeafIndex {
if txns[i].SiafundInputs[j].Parent.StateElement.LeafIndex != types.UnassignedLeafIndex {
continue
}
se, ok := confirmedStateElements[types.Hash256(txns[i].SiafundInputs[j].Parent.ID)]
Expand Down
Loading