not necessary to store value

This commit is contained in:
Brannon King 2021-07-19 19:30:00 -04:00 committed by Roy Lee
parent 9937f66b6a
commit 26e4083f38
8 changed files with 28 additions and 48 deletions

View file

@ -114,15 +114,14 @@ func (h *handler) handleTxOuts(ct *claimtrie.ClaimTrie) error {
var id change.ClaimID var id change.ClaimID
name := cs.Name() name := cs.Name()
amt := txOut.Value amt := txOut.Value
value := cs.Value()
switch cs.Opcode() { switch cs.Opcode() {
case txscript.OP_CLAIMNAME: case txscript.OP_CLAIMNAME:
id = change.NewClaimID(op) id = change.NewClaimID(op)
err = ct.AddClaim(name, op, id, amt, value) err = ct.AddClaim(name, op, id, amt)
case txscript.OP_SUPPORTCLAIM: case txscript.OP_SUPPORTCLAIM:
copy(id[:], cs.ClaimID()) copy(id[:], cs.ClaimID())
err = ct.AddSupport(name, value, op, amt, id) err = ct.AddSupport(name, op, amt, id)
case txscript.OP_UPDATECLAIM: case txscript.OP_UPDATECLAIM:
// old code wouldn't run the update if name or claimID didn't match existing data // old code wouldn't run the update if name or claimID didn't match existing data
// that was a safety feature, but it should have rejected the transaction instead // that was a safety feature, but it should have rejected the transaction instead
@ -135,7 +134,7 @@ func (h *handler) handleTxOuts(ct *claimtrie.ClaimTrie) error {
} }
delete(h.spent, id.Key()) delete(h.spent, id.Key())
err = ct.UpdateClaim(name, op, amt, id, value) err = ct.UpdateClaim(name, op, amt, id)
} }
if err != nil { if err != nil {
return errors.Wrapf(err, "handleTxOuts") return errors.Wrapf(err, "handleTxOuts")

View file

@ -20,7 +20,6 @@ type Change struct {
ClaimID ClaimID ClaimID ClaimID
OutPoint wire.OutPoint OutPoint wire.OutPoint
Amount int64 Amount int64
Value []byte
ActiveHeight int32 // for normalization fork ActiveHeight int32 // for normalization fork
VisibleHeight int32 VisibleHeight int32
@ -51,8 +50,3 @@ func (c Change) SetAmount(amt int64) Change {
c.Amount = amt c.Amount = amt
return c return c
} }
func (c Change) SetValue(value []byte) Change {
c.Value = value
return c
}

View file

@ -161,7 +161,7 @@ func New(cfg config.Config) (*ClaimTrie, error) {
} }
// AddClaim adds a Claim to the ClaimTrie. // AddClaim adds a Claim to the ClaimTrie.
func (ct *ClaimTrie) AddClaim(name []byte, op wire.OutPoint, id change.ClaimID, amt int64, val []byte) error { func (ct *ClaimTrie) AddClaim(name []byte, op wire.OutPoint, id change.ClaimID, amt int64) error {
chg := change.Change{ chg := change.Change{
Type: change.AddClaim, Type: change.AddClaim,
@ -169,14 +169,13 @@ func (ct *ClaimTrie) AddClaim(name []byte, op wire.OutPoint, id change.ClaimID,
OutPoint: op, OutPoint: op,
Amount: amt, Amount: amt,
ClaimID: id, ClaimID: id,
Value: val,
} }
return ct.forwardNodeChange(chg) return ct.forwardNodeChange(chg)
} }
// UpdateClaim updates a Claim in the ClaimTrie. // UpdateClaim updates a Claim in the ClaimTrie.
func (ct *ClaimTrie) UpdateClaim(name []byte, op wire.OutPoint, amt int64, id change.ClaimID, val []byte) error { func (ct *ClaimTrie) UpdateClaim(name []byte, op wire.OutPoint, amt int64, id change.ClaimID) error {
chg := change.Change{ chg := change.Change{
Type: change.UpdateClaim, Type: change.UpdateClaim,
@ -184,7 +183,6 @@ func (ct *ClaimTrie) UpdateClaim(name []byte, op wire.OutPoint, amt int64, id ch
OutPoint: op, OutPoint: op,
Amount: amt, Amount: amt,
ClaimID: id, ClaimID: id,
Value: val,
} }
return ct.forwardNodeChange(chg) return ct.forwardNodeChange(chg)
@ -204,7 +202,7 @@ func (ct *ClaimTrie) SpendClaim(name []byte, op wire.OutPoint, id change.ClaimID
} }
// AddSupport adds a Support to the ClaimTrie. // AddSupport adds a Support to the ClaimTrie.
func (ct *ClaimTrie) AddSupport(name []byte, value []byte, op wire.OutPoint, amt int64, id change.ClaimID) error { func (ct *ClaimTrie) AddSupport(name []byte, op wire.OutPoint, amt int64, id change.ClaimID) error {
chg := change.Change{ chg := change.Change{
Type: change.AddSupport, Type: change.AddSupport,
@ -212,7 +210,6 @@ func (ct *ClaimTrie) AddSupport(name []byte, value []byte, op wire.OutPoint, amt
OutPoint: op, OutPoint: op,
Amount: amt, Amount: amt,
ClaimID: id, ClaimID: id,
Value: value,
} }
return ct.forwardNodeChange(chg) return ct.forwardNodeChange(chg)

View file

@ -52,16 +52,16 @@ func TestFixedHashes(t *testing.T) {
tx3 := buildTx(tx2.TxHash()) tx3 := buildTx(tx2.TxHash())
tx4 := buildTx(tx3.TxHash()) tx4 := buildTx(tx3.TxHash())
err = ct.AddClaim(b("test"), tx1.TxIn[0].PreviousOutPoint, change.NewClaimID(tx1.TxIn[0].PreviousOutPoint), 50, nil) err = ct.AddClaim(b("test"), tx1.TxIn[0].PreviousOutPoint, change.NewClaimID(tx1.TxIn[0].PreviousOutPoint), 50)
r.NoError(err) r.NoError(err)
err = ct.AddClaim(b("test2"), tx2.TxIn[0].PreviousOutPoint, change.NewClaimID(tx2.TxIn[0].PreviousOutPoint), 50, nil) err = ct.AddClaim(b("test2"), tx2.TxIn[0].PreviousOutPoint, change.NewClaimID(tx2.TxIn[0].PreviousOutPoint), 50)
r.NoError(err) r.NoError(err)
err = ct.AddClaim(b("test"), tx3.TxIn[0].PreviousOutPoint, change.NewClaimID(tx3.TxIn[0].PreviousOutPoint), 50, nil) err = ct.AddClaim(b("test"), tx3.TxIn[0].PreviousOutPoint, change.NewClaimID(tx3.TxIn[0].PreviousOutPoint), 50)
r.NoError(err) r.NoError(err)
err = ct.AddClaim(b("tes"), tx4.TxIn[0].PreviousOutPoint, change.NewClaimID(tx4.TxIn[0].PreviousOutPoint), 50, nil) err = ct.AddClaim(b("tes"), tx4.TxIn[0].PreviousOutPoint, change.NewClaimID(tx4.TxIn[0].PreviousOutPoint), 50)
r.NoError(err) r.NoError(err)
err = ct.AppendBlock() err = ct.AppendBlock()
@ -89,27 +89,27 @@ func TestNormalizationFork(t *testing.T) {
hash := chainhash.HashH([]byte{1, 2, 3}) hash := chainhash.HashH([]byte{1, 2, 3})
o1 := wire.OutPoint{Hash: hash, Index: 1} o1 := wire.OutPoint{Hash: hash, Index: 1}
err = ct.AddClaim([]byte("AÑEJO"), o1, change.NewClaimID(o1), 10, nil) err = ct.AddClaim([]byte("AÑEJO"), o1, change.NewClaimID(o1), 10)
r.NoError(err) r.NoError(err)
o2 := wire.OutPoint{Hash: hash, Index: 2} o2 := wire.OutPoint{Hash: hash, Index: 2}
err = ct.AddClaim([]byte("AÑejo"), o2, change.NewClaimID(o2), 5, nil) err = ct.AddClaim([]byte("AÑejo"), o2, change.NewClaimID(o2), 5)
r.NoError(err) r.NoError(err)
o3 := wire.OutPoint{Hash: hash, Index: 3} o3 := wire.OutPoint{Hash: hash, Index: 3}
err = ct.AddClaim([]byte("あてはまる"), o3, change.NewClaimID(o3), 5, nil) err = ct.AddClaim([]byte("あてはまる"), o3, change.NewClaimID(o3), 5)
r.NoError(err) r.NoError(err)
o4 := wire.OutPoint{Hash: hash, Index: 4} o4 := wire.OutPoint{Hash: hash, Index: 4}
err = ct.AddClaim([]byte("Aḿlie"), o4, change.NewClaimID(o4), 5, nil) err = ct.AddClaim([]byte("Aḿlie"), o4, change.NewClaimID(o4), 5)
r.NoError(err) r.NoError(err)
o5 := wire.OutPoint{Hash: hash, Index: 5} o5 := wire.OutPoint{Hash: hash, Index: 5}
err = ct.AddClaim([]byte("TEST"), o5, change.NewClaimID(o5), 5, nil) err = ct.AddClaim([]byte("TEST"), o5, change.NewClaimID(o5), 5)
r.NoError(err) r.NoError(err)
o6 := wire.OutPoint{Hash: hash, Index: 6} o6 := wire.OutPoint{Hash: hash, Index: 6}
err = ct.AddClaim([]byte("test"), o6, change.NewClaimID(o6), 7, nil) err = ct.AddClaim([]byte("test"), o6, change.NewClaimID(o6), 7)
r.NoError(err) r.NoError(err)
err = ct.AppendBlock() err = ct.AppendBlock()
@ -122,7 +122,7 @@ func TestNormalizationFork(t *testing.T) {
r.Equal(int32(1), n.TakenOverAt) r.Equal(int32(1), n.TakenOverAt)
o7 := wire.OutPoint{Hash: hash, Index: 7} o7 := wire.OutPoint{Hash: hash, Index: 7}
err = ct.AddClaim([]byte("aÑEJO"), o7, change.NewClaimID(o7), 8, nil) err = ct.AddClaim([]byte("aÑEJO"), o7, change.NewClaimID(o7), 8)
r.NoError(err) r.NoError(err)
err = ct.AppendBlock() err = ct.AppendBlock()
@ -153,7 +153,7 @@ func TestActivationsOnNormalizationFork(t *testing.T) {
hash := chainhash.HashH([]byte{1, 2, 3}) hash := chainhash.HashH([]byte{1, 2, 3})
o7 := wire.OutPoint{Hash: hash, Index: 7} o7 := wire.OutPoint{Hash: hash, Index: 7}
err = ct.AddClaim([]byte("A"), o7, change.NewClaimID(o7), 1, nil) err = ct.AddClaim([]byte("A"), o7, change.NewClaimID(o7), 1)
r.NoError(err) r.NoError(err)
err = ct.AppendBlock() err = ct.AppendBlock()
r.NoError(err) r.NoError(err)
@ -164,7 +164,7 @@ func TestActivationsOnNormalizationFork(t *testing.T) {
verifyBestIndex(t, ct, "A", 7, 1) verifyBestIndex(t, ct, "A", 7, 1)
o8 := wire.OutPoint{Hash: hash, Index: 8} o8 := wire.OutPoint{Hash: hash, Index: 8}
err = ct.AddClaim([]byte("A"), o8, change.NewClaimID(o8), 2, nil) err = ct.AddClaim([]byte("A"), o8, change.NewClaimID(o8), 2)
r.NoError(err) r.NoError(err)
err = ct.AppendBlock() err = ct.AppendBlock()
r.NoError(err) r.NoError(err)
@ -199,15 +199,15 @@ func TestNormalizationSortOrder(t *testing.T) {
hash := chainhash.HashH([]byte{1, 2, 3}) hash := chainhash.HashH([]byte{1, 2, 3})
o1 := wire.OutPoint{Hash: hash, Index: 1} o1 := wire.OutPoint{Hash: hash, Index: 1}
err = ct.AddClaim([]byte("A"), o1, change.NewClaimID(o1), 1, nil) err = ct.AddClaim([]byte("A"), o1, change.NewClaimID(o1), 1)
r.NoError(err) r.NoError(err)
o2 := wire.OutPoint{Hash: hash, Index: 2} o2 := wire.OutPoint{Hash: hash, Index: 2}
err = ct.AddClaim([]byte("A"), o2, change.NewClaimID(o2), 2, nil) err = ct.AddClaim([]byte("A"), o2, change.NewClaimID(o2), 2)
r.NoError(err) r.NoError(err)
o3 := wire.OutPoint{Hash: hash, Index: 3} o3 := wire.OutPoint{Hash: hash, Index: 3}
err = ct.AddClaim([]byte("a"), o3, change.NewClaimID(o3), 3, nil) err = ct.AddClaim([]byte("a"), o3, change.NewClaimID(o3), 3)
r.NoError(err) r.NoError(err)
err = ct.AppendBlock() err = ct.AppendBlock()
@ -246,11 +246,11 @@ func TestRebuild(t *testing.T) {
hash := chainhash.HashH([]byte{1, 2, 3}) hash := chainhash.HashH([]byte{1, 2, 3})
o1 := wire.OutPoint{Hash: hash, Index: 1} o1 := wire.OutPoint{Hash: hash, Index: 1}
err = ct.AddClaim([]byte("test1"), o1, change.NewClaimID(o1), 1, nil) err = ct.AddClaim([]byte("test1"), o1, change.NewClaimID(o1), 1)
r.NoError(err) r.NoError(err)
o2 := wire.OutPoint{Hash: hash, Index: 2} o2 := wire.OutPoint{Hash: hash, Index: 2}
err = ct.AddClaim([]byte("test2"), o2, change.NewClaimID(o2), 2, nil) err = ct.AddClaim([]byte("test2"), o2, change.NewClaimID(o2), 2)
r.NoError(err) r.NoError(err)
err = ct.AppendBlock() err = ct.AppendBlock()

View file

@ -135,16 +135,16 @@ var chainReplayCmd = &cobra.Command{
switch chg.Type { switch chg.Type {
case change.AddClaim: case change.AddClaim:
err = ct.AddClaim(chg.Name, chg.OutPoint, chg.ClaimID, chg.Amount, chg.Value) err = ct.AddClaim(chg.Name, chg.OutPoint, chg.ClaimID, chg.Amount)
case change.UpdateClaim: case change.UpdateClaim:
err = ct.UpdateClaim(chg.Name, chg.OutPoint, chg.Amount, chg.ClaimID, chg.Value) err = ct.UpdateClaim(chg.Name, chg.OutPoint, chg.Amount, chg.ClaimID)
case change.SpendClaim: case change.SpendClaim:
err = ct.SpendClaim(chg.Name, chg.OutPoint, chg.ClaimID) err = ct.SpendClaim(chg.Name, chg.OutPoint, chg.ClaimID)
case change.AddSupport: case change.AddSupport:
err = ct.AddSupport(chg.Name, chg.Value, chg.OutPoint, chg.Amount, chg.ClaimID) err = ct.AddSupport(chg.Name, chg.OutPoint, chg.Amount, chg.ClaimID)
case change.SpendSupport: case change.SpendSupport:
err = ct.SpendSupport(chg.Name, chg.OutPoint, chg.ClaimID) err = ct.SpendSupport(chg.Name, chg.OutPoint, chg.ClaimID)

View file

@ -27,7 +27,6 @@ type Claim struct {
AcceptedAt int32 // when arrived (aka, originally landed in block) AcceptedAt int32 // when arrived (aka, originally landed in block)
ActiveAt int32 // AcceptedAt + actual delay ActiveAt int32 // AcceptedAt + actual delay
Status Status Status Status
Value []byte
VisibleAt int32 VisibleAt int32
} }
@ -51,11 +50,6 @@ func (c *Claim) setActiveAt(height int32) *Claim {
return c return c
} }
func (c *Claim) SetValue(value []byte) *Claim {
c.Value = value
return c
}
func (c *Claim) setStatus(status Status) *Claim { func (c *Claim) setStatus(status Status) *Claim {
c.Status = status c.Status = status
return c return c

View file

@ -44,7 +44,6 @@ func (n *Node) ApplyChange(chg change.Change, delay int32) error {
ClaimID: chg.ClaimID, ClaimID: chg.ClaimID,
AcceptedAt: chg.Height, // not tracking original height in this version (but we could) AcceptedAt: chg.Height, // not tracking original height in this version (but we could)
ActiveAt: chg.Height + delay, ActiveAt: chg.Height + delay,
Value: chg.Value,
VisibleAt: visibleAt, VisibleAt: visibleAt,
} }
old := n.Claims.find(byOut(chg.OutPoint)) // TODO: remove this after proving ResetHeight works old := n.Claims.find(byOut(chg.OutPoint)) // TODO: remove this after proving ResetHeight works
@ -72,7 +71,7 @@ func (n *Node) ApplyChange(chg change.Change, delay int32) error {
// Keep its ID, which was generated from the spent claim. // Keep its ID, which was generated from the spent claim.
// And update the rest of properties. // And update the rest of properties.
c.setOutPoint(chg.OutPoint).SetAmt(chg.Amount).SetValue(chg.Value) c.setOutPoint(chg.OutPoint).SetAmt(chg.Amount)
c.setStatus(Accepted) // it was Deactivated in the spend (but we only activate at the end of the block) c.setStatus(Accepted) // it was Deactivated in the spend (but we only activate at the end of the block)
// that's because the old code would put all insertions into the "queue" that was processed at block's end // that's because the old code would put all insertions into the "queue" that was processed at block's end
@ -90,7 +89,6 @@ func (n *Node) ApplyChange(chg change.Change, delay int32) error {
Amount: chg.Amount, Amount: chg.Amount,
ClaimID: chg.ClaimID, ClaimID: chg.ClaimID,
AcceptedAt: chg.Height, AcceptedAt: chg.Height,
Value: chg.Value,
ActiveAt: chg.Height + delay, ActiveAt: chg.Height + delay,
VisibleAt: visibleAt, VisibleAt: visibleAt,
}) })

View file

@ -86,7 +86,6 @@ func (nm *NormalizingManager) addNormalizationForkChangesIfNecessary(height int3
OutPoint: c.OutPoint, OutPoint: c.OutPoint,
ClaimID: c.ClaimID, ClaimID: c.ClaimID,
Amount: c.Amount, Amount: c.Amount,
Value: c.Value,
ActiveHeight: c.ActiveAt, // necessary to match the old hash ActiveHeight: c.ActiveAt, // necessary to match the old hash
VisibleHeight: height, // necessary to match the old hash; it would have been much better without VisibleHeight: height, // necessary to match the old hash; it would have been much better without
}) })
@ -105,7 +104,6 @@ func (nm *NormalizingManager) addNormalizationForkChangesIfNecessary(height int3
OutPoint: c.OutPoint, OutPoint: c.OutPoint,
ClaimID: c.ClaimID, ClaimID: c.ClaimID,
Amount: c.Amount, Amount: c.Amount,
Value: c.Value,
ActiveHeight: c.ActiveAt, ActiveHeight: c.ActiveAt,
VisibleHeight: height, VisibleHeight: height,
}) })