-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into morpheusvm-tutorial-update
- Loading branch information
Showing
41 changed files
with
4,329 additions
and
239 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"to": "0x0102030405060708090a0b0c0d0e0f101112131400000000000000000000000000", | ||
"to": "0x0102030405060708090a0b0c0d0e0f10111213140000000000000000000000000020db0e6c", | ||
"value": 1000, | ||
"memo": "aGk=" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright (C) 2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package chain | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/ava-labs/hypersdk/utils" | ||
) | ||
|
||
type Assembler struct { | ||
vm VM | ||
} | ||
|
||
func (a *Assembler) AssembleBlock( | ||
ctx context.Context, | ||
parent *StatefulBlock, | ||
timestamp int64, | ||
blockHeight uint64, | ||
txs []*Transaction, | ||
) (*StatefulBlock, error) { | ||
ctx, span := a.vm.Tracer().Start(ctx, "chain.AssembleBlock") | ||
defer span.End() | ||
|
||
parentView, err := parent.View(ctx, true) | ||
if err != nil { | ||
return nil, err | ||
} | ||
parentStateRoot, err := parentView.GetMerkleRoot(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
blk := &StatelessBlock{ | ||
Prnt: parent.ID(), | ||
Tmstmp: timestamp, | ||
Hght: blockHeight, | ||
Txs: txs, | ||
StateRoot: parentStateRoot, | ||
} | ||
for _, tx := range txs { | ||
blk.authCounts[tx.Auth.GetTypeID()]++ | ||
} | ||
|
||
blkBytes, err := blk.Marshal() | ||
if err != nil { | ||
return nil, err | ||
} | ||
b := &StatefulBlock{ | ||
StatelessBlock: blk, | ||
t: time.UnixMilli(blk.Tmstmp), | ||
bytes: blkBytes, | ||
accepted: false, | ||
vm: a.vm, | ||
id: utils.ToID(blkBytes), | ||
} | ||
return b, b.populateTxs(ctx) // TODO: simplify since txs are guaranteed to already be de-duplicated here | ||
} | ||
|
||
func (a *Assembler) ExecuteBlock( | ||
ctx context.Context, | ||
b *StatefulBlock, | ||
) (*ExecutedBlock, error) { | ||
ctx, span := a.vm.Tracer().Start(ctx, "chain.ExecuteBlock") | ||
defer span.End() | ||
|
||
if err := b.Verify(ctx); err != nil { | ||
return nil, err | ||
} | ||
|
||
return NewExecutedBlockFromStateful(b), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.