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
name := cs.Name()
amt := txOut.Value
value := cs.Value()
switch cs.Opcode() {
case txscript.OP_CLAIMNAME:
id = change.NewClaimID(op)
err = ct.AddClaim(name, op, id, amt, value)
err = ct.AddClaim(name, op, id, amt)
case txscript.OP_SUPPORTCLAIM:
copy(id[:], cs.ClaimID())
err = ct.AddSupport(name, value, op, amt, id)
err = ct.AddSupport(name, op, amt, id)
case txscript.OP_UPDATECLAIM:
// 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
@ -135,7 +134,7 @@ func (h *handler) handleTxOuts(ct *claimtrie.ClaimTrie) error {
}
delete(h.spent, id.Key())
err = ct.UpdateClaim(name, op, amt, id, value)
err = ct.UpdateClaim(name, op, amt, id)
}
if err != nil {
return errors.Wrapf(err, "handleTxOuts")

View file

@ -20,7 +20,6 @@ type Change struct {
ClaimID ClaimID
OutPoint wire.OutPoint
Amount int64
Value []byte
ActiveHeight int32 // for normalization fork
VisibleHeight int32
@ -51,8 +50,3 @@ func (c Change) SetAmount(amt int64) Change {
c.Amount = amt
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.
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{
Type: change.AddClaim,
@ -169,14 +169,13 @@ func (ct *ClaimTrie) AddClaim(name []byte, op wire.OutPoint, id change.ClaimID,
OutPoint: op,
Amount: amt,
ClaimID: id,
Value: val,
}
return ct.forwardNodeChange(chg)
}
// 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{
Type: change.UpdateClaim,
@ -184,7 +183,6 @@ func (ct *ClaimTrie) UpdateClaim(name []byte, op wire.OutPoint, amt int64, id ch
OutPoint: op,
Amount: amt,
ClaimID: id,
Value: val,
}
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.
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{
Type: change.AddSupport,
@ -212,7 +210,6 @@ func (ct *ClaimTrie) AddSupport(name []byte, value []byte, op wire.OutPoint, amt
OutPoint: op,
Amount: amt,
ClaimID: id,
Value: value,
}
return ct.forwardNodeChange(chg)

View file

@ -52,16 +52,16 @@ func TestFixedHashes(t *testing.T) {
tx3 := buildTx(tx2.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)
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)
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)
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)
err = ct.AppendBlock()
@ -89,27 +89,27 @@ func TestNormalizationFork(t *testing.T) {
hash := chainhash.HashH([]byte{1, 2, 3})
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)
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)
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)
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)
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)
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)
err = ct.AppendBlock()
@ -122,7 +122,7 @@ func TestNormalizationFork(t *testing.T) {
r.Equal(int32(1), n.TakenOverAt)
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)
err = ct.AppendBlock()
@ -153,7 +153,7 @@ func TestActivationsOnNormalizationFork(t *testing.T) {
hash := chainhash.HashH([]byte{1, 2, 3})
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)
err = ct.AppendBlock()
r.NoError(err)
@ -164,7 +164,7 @@ func TestActivationsOnNormalizationFork(t *testing.T) {
verifyBestIndex(t, ct, "A", 7, 1)
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)
err = ct.AppendBlock()
r.NoError(err)
@ -199,15 +199,15 @@ func TestNormalizationSortOrder(t *testing.T) {
hash := chainhash.HashH([]byte{1, 2, 3})
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)
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)
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)
err = ct.AppendBlock()
@ -246,11 +246,11 @@ func TestRebuild(t *testing.T) {
hash := chainhash.HashH([]byte{1, 2, 3})
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)
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)
err = ct.AppendBlock()

View file

@ -135,16 +135,16 @@ var chainReplayCmd = &cobra.Command{
switch chg.Type {
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:
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:
err = ct.SpendClaim(chg.Name, chg.OutPoint, chg.ClaimID)
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:
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)
ActiveAt int32 // AcceptedAt + actual delay
Status Status
Value []byte
VisibleAt int32
}
@ -51,11 +50,6 @@ func (c *Claim) setActiveAt(height int32) *Claim {
return c
}
func (c *Claim) SetValue(value []byte) *Claim {
c.Value = value
return c
}
func (c *Claim) setStatus(status Status) *Claim {
c.Status = status
return c

View file

@ -44,7 +44,6 @@ func (n *Node) ApplyChange(chg change.Change, delay int32) error {
ClaimID: chg.ClaimID,
AcceptedAt: chg.Height, // not tracking original height in this version (but we could)
ActiveAt: chg.Height + delay,
Value: chg.Value,
VisibleAt: visibleAt,
}
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.
// 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)
// 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,
ClaimID: chg.ClaimID,
AcceptedAt: chg.Height,
Value: chg.Value,
ActiveAt: chg.Height + delay,
VisibleAt: visibleAt,
})

View file

@ -86,7 +86,6 @@ func (nm *NormalizingManager) addNormalizationForkChangesIfNecessary(height int3
OutPoint: c.OutPoint,
ClaimID: c.ClaimID,
Amount: c.Amount,
Value: c.Value,
ActiveHeight: c.ActiveAt, // necessary to match the old hash
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,
ClaimID: c.ClaimID,
Amount: c.Amount,
Value: c.Value,
ActiveHeight: c.ActiveAt,
VisibleHeight: height,
})