Skip to content

Commit bcbac50

Browse files
authored
Merge pull request #735 from dessaya/remove-deps
Remove some bloat
2 parents 6b5ab4c + 2feef9e commit bcbac50

File tree

12 files changed

+291
-312
lines changed

12 files changed

+291
-312
lines changed

go.mod

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@ require (
1313
filippo.io/edwards25519 v1.1.0
1414
fortio.org/safecast v1.0.0
1515
github.com/VictoriaMetrics/fastcache v1.12.2
16-
github.com/Yiling-J/theine-go v0.6.1
1716
github.com/btcsuite/btcd/btcutil v1.1.6
1817
github.com/bygui86/multi-profile/v2 v2.1.0
1918
github.com/coder/websocket v1.8.13
20-
github.com/dgraph-io/ristretto v0.2.0
21-
github.com/dgryski/go-clockpro v0.0.0-20140817124034-edc6d3eeb96e
2219
github.com/dustin/go-humanize v1.0.1
2320
github.com/ethereum/go-ethereum v1.15.5
2421
github.com/golang-jwt/jwt/v5 v5.2.2
@@ -52,15 +49,13 @@ require (
5249
github.com/mitchellh/hashstructure/v2 v2.0.2
5350
github.com/multiformats/go-multiaddr v0.16.0
5451
github.com/pangpanglabs/echoswagger/v2 v2.4.1
55-
github.com/pingcap/go-ycsb v1.0.1
5652
github.com/pkg/errors v0.9.1
5753
github.com/prometheus/client_golang v1.22.0
5854
github.com/samber/lo v1.49.1
5955
github.com/samber/slog-zap/v2 v2.6.2
6056
github.com/spf13/pflag v1.0.6
6157
github.com/stretchr/testify v1.10.0
6258
github.com/testcontainers/testcontainers-go v0.35.0
63-
github.com/tidwall/gjson v1.18.0
6459
github.com/tyler-smith/go-bip39 v1.1.0
6560
github.com/wollac/iota-crypto-demo v0.0.0-20221117162917-b10619eccb98
6661
github.com/zondax/hid v0.9.2
@@ -188,7 +183,6 @@ require (
188183
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
189184
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
190185
github.com/petermattis/goid v0.0.0-20250303134427-723919f7f203 // indirect
191-
github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c // indirect
192186
github.com/pion/datachannel v1.5.10 // indirect
193187
github.com/pion/dtls/v2 v2.2.12 // indirect
194188
github.com/pion/dtls/v3 v3.0.6 // indirect
@@ -229,15 +223,12 @@ require (
229223
github.com/supranational/blst v0.3.14 // indirect
230224
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
231225
github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e // indirect
232-
github.com/tidwall/match v1.1.1 // indirect
233-
github.com/tidwall/pretty v1.2.0 // indirect
234226
github.com/tklauser/go-sysconf v0.3.15 // indirect
235227
github.com/tklauser/numcpus v0.10.0 // indirect
236228
github.com/valyala/bytebufferpool v1.0.0 // indirect
237229
github.com/valyala/fasttemplate v1.2.2 // indirect
238230
github.com/wlynxg/anet v0.0.5 // indirect
239231
github.com/yusufpapurcu/wmi v1.2.4 // indirect
240-
github.com/zeebo/xxh3 v1.0.2 // indirect
241232
go.dedis.ch/fixbuf v1.0.3 // indirect
242233
go.dedis.ch/protobuf v1.0.11 // indirect
243234
go.opentelemetry.io/auto/sdk v1.1.0 // indirect

go.sum

Lines changed: 12 additions & 27 deletions
Large diffs are not rendered by default.

go.work.sum

Lines changed: 222 additions & 2 deletions
Large diffs are not rendered by default.

packages/isc/dry_run_parsers.go

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66
"fmt"
77
"strconv"
88

9-
"github.com/tidwall/gjson"
10-
119
"github.com/iotaledger/wasp/v2/clients/iota-go/iotago"
1210
"github.com/iotaledger/wasp/v2/clients/iota-go/iotago/iotatest"
1311
"github.com/iotaledger/wasp/v2/clients/iota-go/iotajsonrpc"
@@ -22,7 +20,7 @@ type EstimationRequest struct {
2220
GasBudget json.Number
2321
}
2422

25-
func DecodeCreateAndSendRequest(msg *EstimationRequest, cmd iotago.ProgrammableMoveCall, inputs []iotajsonrpc.ProgrammableTransactionBlockPureInput) error {
23+
func DecodeCreateAndSendRequest(msg *EstimationRequest, cmd *iotago.ProgrammableMoveCall, inputs []iotajsonrpc.ProgrammableTransactionBlockPureInput) error {
2624
if len(cmd.Arguments) != 7 {
2725
return errors.New("create_and_send_request has invalid parameters")
2826
}
@@ -60,7 +58,7 @@ func DecodeCreateAndSendRequest(msg *EstimationRequest, cmd iotago.ProgrammableM
6058
return nil
6159
}
6260

63-
func DecodeCoin(assets *Assets, cmd iotago.ProgrammableMoveCall, inputs []iotajsonrpc.ProgrammableTransactionBlockPureInput) error {
61+
func DecodeCoin(assets *Assets, cmd *iotago.ProgrammableMoveCall, inputs []iotajsonrpc.ProgrammableTransactionBlockPureInput) error {
6462
var err error
6563
if len(cmd.Arguments) != 2 {
6664
return fmt.Errorf("malformed PTB")
@@ -82,7 +80,7 @@ func DecodeCoin(assets *Assets, cmd iotago.ProgrammableMoveCall, inputs []iotajs
8280
return nil
8381
}
8482

85-
func DecodeAsset(assets *Assets, cmd iotago.ProgrammableMoveCall, inputs []iotajsonrpc.ProgrammableTransactionBlockPureInput) error {
83+
func DecodeAsset(assets *Assets, cmd *iotago.ProgrammableMoveCall, inputs []iotajsonrpc.ProgrammableTransactionBlockPureInput) error {
8684
var err error
8785
if len(cmd.Arguments) != 2 {
8886
return fmt.Errorf("malformed PTB")
@@ -114,74 +112,56 @@ func DecodeAsset(assets *Assets, cmd iotago.ProgrammableMoveCall, inputs []iotaj
114112
// I don't expect it to change often if ever, so that seems to be a straight forward way.
115113
func DecodeDryRunTransaction(dryRunRes *iotajsonrpc.DryRunTransactionBlockResponse) (*Assets, *EstimationRequest, *cryptolib.Address, error) {
116114
tx := dryRunRes.Input.Data.V1.Transaction.Data.ProgrammableTransaction
117-
cmds := gjson.ParseBytes(tx.Commands)
118-
var err error
115+
116+
var cmds []struct {
117+
MoveCall *iotago.ProgrammableMoveCall `json:"MoveCall,omitempty"`
118+
}
119+
if err := json.Unmarshal(tx.Commands, &cmds); err != nil {
120+
return nil, nil, cryptolib.NewEmptyAddress(), fmt.Errorf("can't decode dry run response: %w", err)
121+
}
119122

120123
assets := NewAssets(0)
121124
request := &EstimationRequest{
122125
Message: iscmove.Message{},
123126
}
124127

125-
cmds.ForEach(func(key, value gjson.Result) bool {
126-
if moveCall := value.Get("MoveCall"); moveCall.Exists() {
127-
var cmd iotago.ProgrammableMoveCall
128-
err = json.Unmarshal([]byte(moveCall.String()), &cmd)
129-
if err != nil {
130-
err = fmt.Errorf("can't decode dry run response: %w", err)
131-
return false
132-
}
133-
128+
for _, moveCall := range cmds {
129+
if cmd := moveCall.MoveCall; cmd != nil {
134130
// take all placed coins into assets
135131
if cmd.Function == "place_coin" {
136132
var inputs []iotajsonrpc.ProgrammableTransactionBlockPureInput
137-
err = json.Unmarshal(tx.Inputs, &inputs)
138-
if err != nil {
139-
err = fmt.Errorf("can't decode place_coin command: %w", err)
140-
return false
133+
if err := json.Unmarshal(tx.Inputs, &inputs); err != nil {
134+
return nil, nil, cryptolib.NewEmptyAddress(), fmt.Errorf("can't decode place_coin command: %w", err)
141135
}
142136

143-
err = DecodeCoin(assets, cmd, inputs)
144-
if err != nil {
145-
err = fmt.Errorf("can't decode place_coin command: %w", err)
146-
return false
137+
if err := DecodeCoin(assets, cmd, inputs); err != nil {
138+
return nil, nil, cryptolib.NewEmptyAddress(), fmt.Errorf("can't decode place_coin command: %w", err)
147139
}
148140
}
149141

150142
if cmd.Function == "place_asset" {
151143
var inputs []iotajsonrpc.ProgrammableTransactionBlockPureInput
152-
err = json.Unmarshal(tx.Inputs, &inputs)
153-
if err != nil {
154-
err = fmt.Errorf("can't decode place_asset command: %w", err)
155-
return false
144+
if err := json.Unmarshal(tx.Inputs, &inputs); err != nil {
145+
return nil, nil, cryptolib.NewEmptyAddress(), fmt.Errorf("can't decode place_asset command: %w", err)
156146
}
157147

158-
err = DecodeAsset(assets, cmd, inputs)
159-
if err != nil {
160-
err = fmt.Errorf("can't decode place_asset command: %w", err)
161-
return false
148+
if err := DecodeAsset(assets, cmd, inputs); err != nil {
149+
return nil, nil, cryptolib.NewEmptyAddress(), fmt.Errorf("can't decode place_asset command: %w", err)
162150
}
163151
}
164152

165153
if cmd.Function == "create_and_send_request" {
166154
var inputs []iotajsonrpc.ProgrammableTransactionBlockPureInput
167-
err = json.Unmarshal(tx.Inputs, &inputs)
168-
if err != nil {
169-
err = fmt.Errorf("can't decode create_and_send_request command: %w", err)
170-
return false
155+
if err := json.Unmarshal(tx.Inputs, &inputs); err != nil {
156+
return nil, nil, cryptolib.NewEmptyAddress(), fmt.Errorf("can't decode create_and_send_request command: %w", err)
171157
}
172158

173-
err = DecodeCreateAndSendRequest(request, cmd, inputs)
174-
if err != nil {
175-
err = fmt.Errorf("can't decode create_and_send_request command: %w", err)
176-
return false
159+
if err := DecodeCreateAndSendRequest(request, cmd, inputs); err != nil {
160+
return nil, nil, cryptolib.NewEmptyAddress(), fmt.Errorf("can't decode create_and_send_request command: %w", err)
177161
}
178162
}
179163
}
180-
return true // Continue iteration
181-
})
182-
if err != nil {
183-
return nil, nil, cryptolib.NewEmptyAddress(), err
184164
}
185165

186-
return assets, request, cryptolib.NewAddressFromIota(&dryRunRes.Input.Data.V1.Sender), err
166+
return assets, request, cryptolib.NewAddressFromIota(&dryRunRes.Input.Data.V1.Sender), nil
187167
}

packages/trie/test/bench_test.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"io"
66
"math/rand/v2"
7+
"strconv"
78
"testing"
89

910
"github.com/samber/lo"
@@ -13,6 +14,20 @@ import (
1314
"github.com/iotaledger/wasp/v2/packages/trie"
1415
)
1516

17+
type valueMaker struct {
18+
z *rand.Zipf
19+
}
20+
21+
func newValueMaker() *valueMaker {
22+
return &valueMaker{
23+
z: rand.NewZipf(rand.New(rand.NewChaCha8([32]byte{})), 1.1, 1, 1000),
24+
}
25+
}
26+
27+
func (g *valueMaker) Next() string {
28+
return strconv.FormatUint(g.z.Uint64(), 10)
29+
}
30+
1631
func keyMaker() func() []byte {
1732
// small alphabet to force keys to have common prefixes
1833
const alphabet = "abc"
@@ -33,7 +48,7 @@ func makeTrie(n int) (*InMemoryKVStore, []trie.Hash) {
3348
store := NewInMemoryKVStore()
3449
roots := []trie.Hash{lo.Must(trie.NewTrieRW(store).InitRoot(true))}
3550
makeKey := keyMaker()
36-
values := NewScrambledZipfian(1000, 0)
51+
values := newValueMaker()
3752

3853
for range n {
3954
tr := lo.Must(trie.NewDraft(store, roots[len(roots)-1]))
@@ -58,8 +73,8 @@ func BenchmarkTakeSnapshot(b *testing.B) {
5873
store, roots := makeTrie(1)
5974
r := trie.NewTrieRFromRoot(store, roots[len(roots)-1])
6075
store.ResetStats()
61-
b.ResetTimer()
62-
for i := 0; i < b.N; i++ {
76+
77+
for b.Loop() {
6378
err := r.TakeSnapshot(io.Discard)
6479
require.NoError(b, err)
6580
}
@@ -74,7 +89,6 @@ func BenchmarkRestoreSnapshot(b *testing.B) {
7489
// 56646487 ns/op 13083 kvs/op 7443 reads/op 27590744 B/op 386339 allocs/op
7590
// reads/op measures the amount of times the DB is called to fetch data (which is the bottleneck when using RocksDB)
7691

77-
b.StopTimer()
7892
buf := bytes.NewBuffer(nil)
7993
{
8094
store, roots := makeTrie(1)
@@ -84,7 +98,7 @@ func BenchmarkRestoreSnapshot(b *testing.B) {
8498
}
8599

86100
stats := InMemoryKVStoreStats{}
87-
for i := 0; i < b.N; i++ {
101+
for b.Loop() {
88102
newStore := NewInMemoryKVStore()
89103
newStore.Stats = stats
90104
b.StartTimer()
@@ -104,11 +118,10 @@ func BenchmarkPrune(b *testing.B) {
104118
// 24594662 ns/op 16476 kvs/op 9132 reads/op 19913272 B/op 307635 allocs/op
105119
// reads/op measures the amount of times the DB is called to fetch data (which is the bottleneck when using RocksDB)
106120

107-
b.StopTimer()
108121
store, roots := makeTrie(3)
109122
penultimateRoot := roots[len(roots)-2]
110123
stats := InMemoryKVStoreStats{}
111-
for i := 0; i < b.N; i++ {
124+
for b.Loop() {
112125
storeClone := NewInMemoryKVStore()
113126
lo.Must0(kvstore.Copy(store.m, storeClone.m))
114127
storeClone.Stats = stats
@@ -129,16 +142,14 @@ func BenchmarkCommit(b *testing.B) {
129142
// 9486585 ns/op 4221 kvs/op 2 reads/op 6279097 B/op 108977 allocs/op
130143
// reads/op measures the amount of times the DB is called to fetch data (which is the bottleneck when using RocksDB)
131144

132-
b.StopTimer()
133-
134145
store := NewInMemoryKVStore()
135146
stats := store.Stats
136147

137148
makeKey := keyMaker()
138-
values := NewScrambledZipfian(1000, 0)
149+
values := newValueMaker()
139150

140151
root := lo.Must(trie.NewTrieRW(store).InitRoot(true))
141-
for i := 0; i < b.N; i++ {
152+
for b.Loop() {
142153
tr := lo.Must(trie.NewDraft(store, root))
143154
for range 1000 {
144155
key := makeKey()

0 commit comments

Comments
 (0)