Skip to content

Commit

Permalink
Merge branch 'tsachi/refactor_validity_window3' of github.com:ava-lab…
Browse files Browse the repository at this point in the history
…s/hypersdk into tsachi/refactor_validity_window3
  • Loading branch information
tsachiherman committed Dec 23, 2024
2 parents c87b033 + dd419bb commit 293c6b9
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 34 deletions.
2 changes: 1 addition & 1 deletion chain/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func (p *Processor) executeTxs(

// Prefetch state keys from disk
txID := tx.GetID()
if err := f.Fetch(ctx, txID, stateKeys); err != nil {
if err := f.Fetch(ctx, txID, stateKeys.WithoutPermissions()); err != nil {
return nil, nil, err
}
e.Run(stateKeys, func() error {
Expand Down
20 changes: 11 additions & 9 deletions docs/tutorials/morpheusvm/4_deploying_vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ Let's get started!

To head over, follow the installation instructions in the Avalanche-CLI [README](https://github.com/ava-labs/avalanche-cli?tab=readme-ov-file#installation).

To verify that your version is at least `2.0.0`, run the following:
To verify that your version is at least `2.0.0`, run `avalanche --version`,
which should give you the following output:

```bash
AVL-0W5L7Y:avalanche-cli rodrigo.villar$ avalanche --version
avalanche version 2.0.0
```

Expand Down Expand Up @@ -354,20 +354,22 @@ We're now ready to use the HyperSDK-CLI!
## CLI Setup

We want to store the private key of our (test!) account
and the RPC endpoint. We can do this by executing the following commands:
and the RPC endpoint. We first store the RPC endpoint:

```bash
./hypersdk-cli endpoint set --endpoint=http://localhost:9650/ext/bc/tutorial/
./hypersdk-cli key set --key=0x323b1d8f4eed5f0da9da93071b034f2dce9d2d22692c172f3cb252a64ddfafd01b057de320297c29ad0c1f589ea216869cf1938d88c9fbd70d6748323dbf2fa7

# Output
Endpoint set to: http://localhost:9650/ext/bc/tutorial/
```

Your command line should look as follows:
Now storing our private key:

```bash
AVL-0W5L7Y:tutorial rodrigo.villar$ ./hypersdk-cli endpoint set --endpoint=http://localhost:9650/ext/bc/tutorial/
Endpoint set to: http://localhost:9650/ext/bc/tutorial/
AVL-0W5L7Y:tutorial rodrigo.villar$ ./hypersdk-cli key set --key=0x323b1d8f4eed5f0da9da93071b034f2dce9d2d22692c172f3cb252a64ddfafd01b057de320297c29ad0c1f589ea216869cf1938d88c9fbd70d6748323dbf2fa7
✅ Key added successfully!
./hypersdk-cli key set --key=0x323b1d8f4eed5f0da9da93071b034f2dce9d2d22692c172f3cb252a64ddfafd01b057de320297c29ad0c1f589ea216869cf1938d88c9fbd70d6748323dbf2fa7

# Output
✅ Key added successfully!
Address: 0x00c4cb545f748a28770042f893784ce85b107389004d6a0e0d6d7518eeae1292d9
```

Expand Down
16 changes: 8 additions & 8 deletions internal/fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type Fetcher struct {
type tx struct {
blockers int
waiter chan struct{}
keys state.Keys
keys []string
}

type task struct {
Expand Down Expand Up @@ -140,18 +140,18 @@ func (f *Fetcher) handleErr(err error) {
// Fetch can be called concurrently.
//
// Invariant: Don't call [Fetch] afer calling [Stop] or [Wait]
func (f *Fetcher) Fetch(ctx context.Context, txID ids.ID, stateKeys state.Keys) error {
func (f *Fetcher) Fetch(ctx context.Context, txID ids.ID, keys []string) error {
f.l.Lock()
if f.err != nil {
f.l.Unlock()
return f.err
}
var (
tx = &tx{keys: stateKeys}
tasks = make([]*task, 0, len(stateKeys))
tx = &tx{keys: keys}
tasks = make([]*task, 0, len(keys))
blockers = 0
)
for k := range stateKeys {
for _, k := range keys {
d, ok := f.keys[k]
if !ok {
f.keys[k] = &key{blocked: []ids.ID{txID}}
Expand Down Expand Up @@ -216,10 +216,10 @@ func (f *Fetcher) Get(txID ids.ID) (map[string][]byte, error) {
f.l.RLock()
defer f.l.RUnlock()
var (
stateKeys = tx.keys
storage = make(map[string][]byte, len(stateKeys))
keys = tx.keys
storage = make(map[string][]byte, len(keys))
)
for k := range stateKeys {
for _, k := range keys {
if v := f.keys[k].cache; v != nil {
if v.exists {
storage[k] = v.v
Expand Down
28 changes: 12 additions & 16 deletions internal/fetcher/fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,14 @@ func TestFetchDifferentKeys(t *testing.T) {
wg.Add(numTxs)

for i := 0; i < numTxs; i++ {
stateKeys := make(state.Keys, (i + 1))
keys := make([]string, (i + 1))
for k := 0; k < i+1; k++ {
// Generate different read keys
stateKeys.Add(ids.GenerateTestID().String(), state.Read)
keys = append(keys, ids.GenerateTestID().String())
}
txID := ids.GenerateTestID()
// Since these are all different keys, we will
// fetch each key from disk
require.NoError(f.Fetch(ctx, txID, stateKeys))
require.NoError(f.Fetch(ctx, txID, keys))
go func() {
defer wg.Done()
// Get keys from cache
Expand Down Expand Up @@ -98,15 +97,14 @@ func TestFetchSameKeys(t *testing.T) {
wg.Add(numTxs)

for i := 0; i < numTxs; i++ {
stateKeys := make(state.Keys, (i + 1))
keys := make([]string, (i + 1))
for k := 0; k < i+1; k++ {
// Generate the same keys
stateKeys.Add(keyBase+strconv.Itoa(k), state.Read)
keys = append(keys, keyBase+strconv.Itoa(k))
}
txID := ids.GenerateTestID()
// We are fetching the same keys, so we should
// be getting subsequent requests from cache
require.NoError(f.Fetch(ctx, txID, stateKeys))
require.NoError(f.Fetch(ctx, txID, keys))
go func() {
defer wg.Done()
storage, err := f.Get(txID)
Expand Down Expand Up @@ -136,18 +134,17 @@ func TestFetchSameKeysSlow(t *testing.T) {
)
wg.Add(numTxs)
for i := 0; i < numTxs; i++ {
stateKeys := make(state.Keys, (i + 1))
keys := make([]string, (i + 1))
for k := 0; k < i+1; k++ {
// Generate the same keys
stateKeys.Add(keyBase+strconv.Itoa(k), state.Read)
keys = append(keys, keyBase+strconv.Itoa(k))
}
txID := ids.GenerateTestID()

// Empty chan to mimic timing out
delay := make(chan struct{})

// Fetch the key
require.NoError(f.Fetch(ctx, txID, stateKeys))
require.NoError(f.Fetch(ctx, txID, keys))
go func() {
defer wg.Done()
// Get the keys from cache
Expand Down Expand Up @@ -183,13 +180,12 @@ func TestFetcherStop(t *testing.T) {
)
wg.Add(numTxs)
for i := 0; i < numTxs; i++ {
stateKeys := make(state.Keys, (i + 1))
keys := make([]string, (i + 1))
for k := 0; k < i+1; k++ {
// Generate the same keys
stateKeys.Add(keyBase+strconv.Itoa(k), state.Read)
keys = append(keys, keyBase+strconv.Itoa(k))
}
txID := ids.GenerateTestID()
err := f.Fetch(ctx, txID, stateKeys)
err := f.Fetch(ctx, txID, keys)
if err != nil {
// Some [Fetch] may return an error.
// This happens after we called [Stop]
Expand Down
9 changes: 9 additions & 0 deletions state/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ func (k Keys) ChunkSizes() ([]uint16, bool) {
return chunks, true
}

// WithoutPermissions returns the keys of k as a slice with permissions removed
func (k Keys) WithoutPermissions() []string {
ks := make([]string, len(k))
for key := range k {
ks = append(ks, key)
}
return ks
}

type keysJSON map[string]Permissions

// MarshalJSON marshals Keys as readable JSON.
Expand Down

0 comments on commit 293c6b9

Please sign in to comment.