Skip to content

Commit

Permalink
Merge branch 'main' into target-metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronbuchwald committed Nov 22, 2024
2 parents 7695645 + 910dd46 commit 1dfbe2d
Show file tree
Hide file tree
Showing 26 changed files with 98 additions and 98 deletions.
2 changes: 1 addition & 1 deletion api/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (i *Indexer) storeTransactions(blk *chain.ExecutedBlock) error {
result := blk.Results[j]
if err := i.storeTransaction(
batch,
tx.ID(),
tx.GetID(),
blk.Block.Tmstmp,
result.Success,
result.Units,
Expand Down
2 changes: 1 addition & 1 deletion api/jsonrpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (j *JSONRPCServer) SubmitTx(
if !rtx.Empty() {
return errTransactionExtraBytes
}
txID := tx.ID()
txID := tx.GetID()
reply.TxID = txID
return j.vm.Submit(ctx, []*chain.Transaction{tx})[0]
}
Expand Down
6 changes: 3 additions & 3 deletions api/ws/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (w *WebSocketServer) AddTxListener(tx *chain.Transaction, c *pubsub.Connect
defer w.txL.Unlock()

// TODO: limit max number of tx listeners a single connection can create
txID := tx.ID()
txID := tx.GetID()
connections, ok := w.txListeners[txID]
if !ok {
connections = pubsub.NewConnections()
Expand Down Expand Up @@ -197,7 +197,7 @@ func (w *WebSocketServer) AcceptBlock(b *chain.ExecutedBlock) error {
defer w.txL.Unlock()
results := b.Results
for i, tx := range b.Block.Txs {
txID := tx.ID()
txID := tx.GetID()
listeners, ok := w.txListeners[txID]
if !ok {
continue
Expand Down Expand Up @@ -251,7 +251,7 @@ func (w *WebSocketServer) MessageCallback() pubsub.Callback {
w.AddTxListener(tx, c)

// Submit will remove from [txListeners] if it is not added
txID := tx.ID()
txID := tx.GetID()
if err := w.vm.Submit(ctx, []*chain.Transaction{tx})[0]; err != nil {
w.logger.Error("failed to submit tx",
zap.Stringer("txID", txID),
Expand Down
4 changes: 2 additions & 2 deletions chain/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,15 @@ func (c *Builder) BuildBlock(ctx context.Context, parentView state.View, parent
// We track pending transactions because an error may cause us
// not to execute restorable transactions.
pendingLock.Lock()
pending[tx.ID()] = tx
pending[tx.GetID()] = tx
pendingLock.Unlock()
e.Run(stateKeys, func() error {
// We use defer here instead of covering all returns because it is
// much easier to manage.
var restore bool
defer func() {
pendingLock.Lock()
delete(pending, tx.ID())
delete(pending, tx.GetID())
pendingLock.Unlock()

if !restore {
Expand Down
6 changes: 3 additions & 3 deletions chain/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ func NewExecutionBlock(block *StatelessBlock) (*ExecutionBlock, error) {
authCounts := make(map[uint8]int)
txsSet := set.NewSet[ids.ID](len(block.Txs))
for _, tx := range block.Txs {
if txsSet.Contains(tx.ID()) {
if txsSet.Contains(tx.GetID()) {
return nil, ErrDuplicateTx
}
txsSet.Add(tx.ID())
txsSet.Add(tx.GetID())
authCounts[tx.Auth.GetTypeID()]++
}

Expand Down Expand Up @@ -336,7 +336,7 @@ func (p *Processor) executeTxs(
}

// Prefetch state keys from disk
txID := tx.ID()
txID := tx.GetID()
if err := f.Fetch(ctx, txID, stateKeys); err != nil {
return nil, nil, err
}
Expand Down
10 changes: 5 additions & 5 deletions chain/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func SignRawActionBytesTx(
return p.Bytes(), p.Err()
}

func (t *TransactionData) Expiry() int64 { return t.Base.Timestamp }
func (t *TransactionData) GetExpiry() int64 { return t.Base.Timestamp }

func (t *TransactionData) MaxFee() uint64 { return t.Base.MaxFee }

Expand Down Expand Up @@ -184,7 +184,7 @@ func (t *Transaction) Bytes() []byte { return t.bytes }

func (t *Transaction) Size() int { return t.size }

func (t *Transaction) ID() ids.ID { return t.id }
func (t *Transaction) GetID() ids.ID { return t.id }

func (t *Transaction) StateKeys(bh BalanceHandler) (state.Keys, error) {
if t.stateKeys != nil {
Expand All @@ -194,7 +194,7 @@ func (t *Transaction) StateKeys(bh BalanceHandler) (state.Keys, error) {

// Verify the formatting of state keys passed by the controller
for i, action := range t.Actions {
for k, v := range action.StateKeys(t.Auth.Actor(), CreateActionID(t.ID(), uint8(i))) {
for k, v := range action.StateKeys(t.Auth.Actor(), CreateActionID(t.GetID(), uint8(i))) {
if !stateKeys.Add(k, v) {
return nil, ErrInvalidKeyValue
}
Expand Down Expand Up @@ -341,7 +341,7 @@ func (t *Transaction) Execute(
actionOutputs = [][]byte{}
)
for i, action := range t.Actions {
actionOutput, err := action.Execute(ctx, r, ts, timestamp, t.Auth.Actor(), CreateActionID(t.ID(), uint8(i)))
actionOutput, err := action.Execute(ctx, r, ts, timestamp, t.Auth.Actor(), CreateActionID(t.GetID(), uint8(i)))
if err != nil {
ts.Rollback(ctx, actionStart)
return &Result{false, utils.ErrBytes(err), actionOutputs, units, fee}, nil
Expand Down Expand Up @@ -407,7 +407,7 @@ func (t *Transaction) MarshalJSON() ([]byte, error) {
}

return json.Marshal(txJSON{
ID: t.ID(),
ID: t.GetID(),
Actions: actionsPacker.Bytes(),
Auth: authPacker.Bytes(),
Base: t.Base,
Expand Down
2 changes: 1 addition & 1 deletion chain/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func TestMarshalUnmarshal(t *testing.T) {
writerPacker := codec.NewWriter(0, consts.NetworkSizeLimit)
err = signedTx.Marshal(writerPacker)
require.NoError(err)
require.Equal(signedTx.ID(), utils.ToID(writerPacker.Bytes()))
require.Equal(signedTx.GetID(), utils.ToID(writerPacker.Bytes()))
require.Equal(signedTx.Bytes(), writerPacker.Bytes())

unsignedTxBytes, err := signedTx.UnsignedBytes()
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/morpheusvm/4_testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (g *TxGenerator) GenerateTx(ctx context.Context, uri string) (*chain.Transa
}

return tx, func(ctx context.Context, require *require.Assertions, uri string) {
confirmTx(ctx, require, uri, tx.ID(), toAddress, 1)
confirmTx(ctx, require, uri, tx.GetID(), toAddress, 1)
}, nil
}
```
Expand Down
12 changes: 6 additions & 6 deletions examples/morpheusvm/cmd/morpheus-cli/cmd/resolutions.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ func sendAndWait(
if txErr != nil {
return false, ids.Empty, txErr
}
if txID == tx.ID() {
if txID == tx.GetID() {
result = txResult
break
}
utils.Outf("{{yellow}}skipping unexpected transaction:{{/}} %s\n", tx.ID())
utils.Outf("{{yellow}}skipping unexpected transaction:{{/}} %s\n", tx.GetID())
}
if printStatus {
status := "❌"
if result.Success {
status = "✅"
}
utils.Outf("%s {{yellow}}txID:{{/}} %s\n", status, tx.ID())
utils.Outf("%s {{yellow}}txID:{{/}} %s\n", status, tx.GetID())
}
return result.Success, tx.ID(), nil
return result.Success, tx.GetID(), nil
}

func handleTx(tx *chain.Transaction, result *chain.Result) {
Expand All @@ -66,7 +66,7 @@ func handleTx(tx *chain.Transaction, result *chain.Result) {
utils.Outf(
"%s {{yellow}}%s{{/}} {{yellow}}actor:{{/}} %s {{yellow}}error:{{/}} [%s] {{yellow}}fee (max %.2f%%):{{/}} %s %s {{yellow}}consumed:{{/}} [%s]\n",
"❌",
tx.ID(),
tx.GetID(),
actor,
result.Error,
float64(result.Fee)/float64(tx.Base.MaxFee)*100,
Expand All @@ -86,7 +86,7 @@ func handleTx(tx *chain.Transaction, result *chain.Result) {
utils.Outf(
"%s {{yellow}}%s{{/}} {{yellow}}actor:{{/}} %s {{yellow}}summary (%s):{{/}} [%s] {{yellow}}fee (max %.2f%%):{{/}} %s %s {{yellow}}consumed:{{/}} [%s]\n",
"✅",
tx.ID(),
tx.GetID(),
actor,
reflect.TypeOf(action),
summaryStr,
Expand Down
2 changes: 1 addition & 1 deletion examples/morpheusvm/tests/workload/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (g *TxGenerator) GenerateTx(ctx context.Context, uri string) (*chain.Transa
}

return tx, func(ctx context.Context, require *require.Assertions, uri string) {
confirmTx(ctx, require, uri, tx.ID(), toAddress, 1)
confirmTx(ctx, require, uri, tx.GetID(), toAddress, 1)
}, nil
}

Expand Down
12 changes: 6 additions & 6 deletions internal/eheap/eheap.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

// Item is the interface that any item put in the heap must adheare to.
type Item interface {
ID() ids.ID
Expiry() int64
GetID() ids.ID
GetExpiry() int64
}

// ExpiryHeap keeps a min heap of [Items] sorted by [Expiry].
Expand All @@ -35,11 +35,11 @@ func New[T Item](items int) *ExpiryHeap[T] {

// Add pushes [item] to eh.
func (eh *ExpiryHeap[T]) Add(item T) {
itemID := item.ID()
itemID := item.GetID()
poolLen := eh.minHeap.Len()
eh.minHeap.Push(&heap.Entry[T, int64]{
ID: itemID,
Val: item.Expiry(),
Val: item.GetExpiry(),
Item: item,
Index: poolLen,
})
Expand All @@ -66,7 +66,7 @@ func (eh *ExpiryHeap[T]) SetMin(val int64) []T {
if !ok {
break
}
if min.Expiry() < val {
if min.GetExpiry() < val {
eh.PopMin() // Assumes that there is not concurrent access to [ExpiryHeap]
removed = append(removed, min)
continue
Expand All @@ -92,7 +92,7 @@ func (eh *ExpiryHeap[T]) PopMin() (T, bool) {
return *new(T), false
}
item := first.Item
eh.Remove(item.ID())
eh.Remove(item.GetID())
return item, true
}

Expand Down
36 changes: 18 additions & 18 deletions internal/eheap/eheap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ type TestItem struct {
timestamp int64
}

func (mti *TestItem) ID() ids.ID {
func (mti *TestItem) GetID() ids.ID {
return mti.id
}

func (mti *TestItem) Sponsor() string {
return mti.sponsor
}

func (mti *TestItem) Expiry() int64 {
func (mti *TestItem) GetExpiry() int64 {
return mti.timestamp
}

Expand All @@ -53,7 +53,7 @@ func TestExpiryHeapAdd(t *testing.T) {
item := GenerateTestItem("sponsor", 1)
eheap.Add(item)
require.Equal(1, eheap.minHeap.Len(), "MinHeap not pushed correctly")
require.True(eheap.minHeap.Has(item.ID()), "MinHeap does not have ID")
require.True(eheap.minHeap.Has(item.GetID()), "MinHeap does not have ID")
}

func TestExpiryHeapRemove(t *testing.T) {
Expand All @@ -64,11 +64,11 @@ func TestExpiryHeapRemove(t *testing.T) {
// Add first
eheap.Add(item)
require.Equal(1, eheap.minHeap.Len(), "MinHeap not pushed correctly")
require.True(eheap.minHeap.Has(item.ID()), "MinHeap does not have ID")
require.True(eheap.minHeap.Has(item.GetID()), "MinHeap does not have ID")
// Remove
eheap.Remove(item.ID())
eheap.Remove(item.GetID())
require.Zero(eheap.minHeap.Len(), "MinHeap not removed")
require.False(eheap.minHeap.Has(item.ID()), "MinHeap still has ID")
require.False(eheap.minHeap.Has(item.GetID()), "MinHeap still has ID")
}

func TestExpiryHeapRemoveEmpty(t *testing.T) {
Expand All @@ -78,7 +78,7 @@ func TestExpiryHeapRemoveEmpty(t *testing.T) {
eheap := New[*TestItem](0)
item := GenerateTestItem("sponsor", 1)
// Require this returns
eheap.Remove(item.ID())
eheap.Remove(item.GetID())
require.True(true, "not true")
}

Expand All @@ -89,18 +89,18 @@ func TestSetMin(t *testing.T) {
for i := int64(0); i <= 9; i++ {
item := GenerateTestItem(sponsor, i)
eheap.Add(item)
require.True(eheap.Has(item.ID()), "TX not included")
require.True(eheap.Has(item.GetID()), "TX not included")
}
// Remove half
removed := eheap.SetMin(5)
require.Len(removed, 5, "Returned an incorrect number of txs.")
// All timestamps less than 5
seen := make(map[int64]bool)
for _, item := range removed {
require.Less(item.Expiry(), int64(5))
_, ok := seen[item.Expiry()]
require.Less(item.GetExpiry(), int64(5))
_, ok := seen[item.GetExpiry()]
require.False(ok, "Incorrect item removed.")
seen[item.Expiry()] = true
seen[item.GetExpiry()] = true
}
// ExpiryHeap has same length
require.Equal(5, eheap.Len(), "ExpiryHeap has incorrect number of txs.")
Expand All @@ -115,7 +115,7 @@ func TestSetMinRemovesAll(t *testing.T) {
item := GenerateTestItem(sponsor, i)
items = append(items, item)
eheap.Add(item)
require.True(eheap.Has(item.ID()), "TX not included")
require.True(eheap.Has(item.GetID()), "TX not included")
}
// Remove more than exists
removed := eheap.SetMin(10)
Expand All @@ -136,19 +136,19 @@ func TestPeekMin(t *testing.T) {
require.Nil(min, "Peek UnitPrice is incorrect")
// Check PeekMin
eheap.Add(itemMed)
require.True(eheap.Has(itemMed.ID()), "TX not included")
require.True(eheap.Has(itemMed.GetID()), "TX not included")
min, ok = eheap.PeekMin()
require.True(ok)
require.Equal(itemMed, min, "Peek value is incorrect")

eheap.Add(itemMin)
require.True(eheap.Has(itemMin.ID()), "TX not included")
require.True(eheap.Has(itemMin.GetID()), "TX not included")
min, ok = eheap.PeekMin()
require.True(ok)
require.Equal(itemMin, min, "Peek value is incorrect")

eheap.Add(itemMax)
require.True(eheap.Has(itemMax.ID()), "TX not included")
require.True(eheap.Has(itemMax.GetID()), "TX not included")
min, ok = eheap.PeekMin()
require.True(ok)
require.Equal(itemMin, min, "Peek value is incorrect")
Expand Down Expand Up @@ -185,9 +185,9 @@ func TestHas(t *testing.T) {

eheap := New[*TestItem](0)
item := GenerateTestItem(testSponsor, 1)
require.False(eheap.Has(item.ID()), "Found an item that was not added.")
require.False(eheap.Has(item.GetID()), "Found an item that was not added.")
eheap.Add(item)
require.True(eheap.Has(item.ID()), "Did not find item.")
require.True(eheap.Has(item.GetID()), "Did not find item.")
}

func TestLen(t *testing.T) {
Expand All @@ -197,7 +197,7 @@ func TestLen(t *testing.T) {
for i := int64(0); i <= 4; i++ {
item := GenerateTestItem(testSponsor, i)
eheap.Add(item)
require.True(eheap.Has(item.ID()), "TX not included")
require.True(eheap.Has(item.GetID()), "TX not included")
}
require.Equal(5, eheap.Len(), "Length of mempool is not as expected.")
}
Loading

0 comments on commit 1dfbe2d

Please sign in to comment.