Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: implement System.Blockchain.GetTransaction and System.Blockchain.GetBlock interops #1034

Merged
merged 7 commits into from
Jun 10, 2020

Conversation

AnnaShaleva
Copy link
Member

closes #1023 and #1025

@AnnaShaleva AnnaShaleva self-assigned this Jun 9, 2020
@codecov
Copy link

codecov bot commented Jun 9, 2020

Codecov Report

Merging #1034 into master will increase coverage by 0.31%.
The diff coverage is 77.27%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1034      +/-   ##
==========================================
+ Coverage   65.64%   65.95%   +0.31%     
==========================================
  Files         190      187       -3     
  Lines       15993    15945      -48     
==========================================
+ Hits        10498    10517      +19     
+ Misses       4981     4909      -72     
- Partials      514      519       +5     
Impacted Files Coverage Δ
pkg/core/interop_neo.go 58.01% <ø> (-3.18%) ⬇️
pkg/core/interops.go 100.00% <ø> (ø)
pkg/interop/blockchain/blockchain.go 0.00% <0.00%> (ø)
pkg/interop/engine/engine.go 0.00% <0.00%> (ø)
pkg/compiler/codegen.go 90.00% <33.33%> (-0.20%) ⬇️
pkg/core/interop_system.go 51.82% <89.58%> (+11.70%) ⬆️
pkg/core/gas_price.go 100.00% <100.00%> (ø)
pkg/core/transaction/attribute.go 11.62% <0.00%> (+7.75%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7ddcc35...8b7abd3. Read the comment docs.

fyrchik
fyrchik previously requested changes Jun 9, 2020
if index > height {
return false
}
return index+MaxTraceableBlocks > height
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return index <= height && index + MaxTraceableBlocks > height ?

func GetTransactions(b Block) []transaction.Transaction {
return []transaction.Transaction{}
func GetTransactions(b Block) []blockchain.Transaction {
return []blockchain.Transaction{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation of this and next interop should also be changed.

Copy link
Contributor

@fyrchik fyrchik Jun 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see they were removed later. Probably worth removing before.

@@ -145,6 +145,10 @@ func bcGetTransactionHeight(ic *interop.Context, v *vm.VM) error {
if err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we return -1 here now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For ErrKeyNotFound sure, we may have dropped it already and it's perfectly fine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to -1.

}
block, err := ic.Chain.GetBlock(hash)
if err != nil || !isTraceableBlock(ic, block.Index) {
v.Estack().PushVal(stackitem.Null{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should return after this.

v.Estack().PushVal(stackitem.Null{})
}
index := v.Estack().Pop().BigInt().Int64()
if index < 0 || index >= int64(len(block.Transactions)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C# implementation uses len-1 (and index+1 below). Probably 1st tx shouldn't be taken into account.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's just to compensate for consensusDataHash, we don't have this problem.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true.

pkg/compiler/codegen.go Outdated Show resolved Hide resolved
pkg/core/transaction/transaction.go Outdated Show resolved Hide resolved
pkg/interop/blockchain/blockchain.go Outdated Show resolved Hide resolved
pkg/interop/blockchain/blockchain.go Outdated Show resolved Hide resolved
pkg/interop/blockchain/blockchain.go Outdated Show resolved Hide resolved
v.Estack().PushVal(stackitem.Null{})
}
index := v.Estack().Pop().BigInt().Int64()
if index < 0 || index >= int64(len(block.Transactions)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's just to compensate for consensusDataHash, we don't have this problem.

pkg/core/interop_system.go Outdated Show resolved Hide resolved
return errors.New("wrong transaction index")
}
tx := block.Transactions[index]
v.Estack().PushVal(tx.ToStackItem())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should put tx's hash here, not tx itself. And we should have a test for this interop also.

pkg/core/block/block.go Outdated Show resolved Hide resolved
pkg/interop/blockchain/blockchain.go Outdated Show resolved Hide resolved
We don't need them anymore.
closes #1023

Now we put on stack stackitem.Array instead of Interop, so we don't
need old transaction-related interops anymore. Removed the following
interops:
	System.Transaction.GetHash
	Neo.Transaction.GetAttributes
	Neo.Transaction.GetHash
	Neo.Transaction.GetWitnesses
	Neo.Attribute.GetData
	Neo.Attribute.GetUsage

Also removed the following duplicated NEO interop:
	Neo.Blockchain.GetTransaction
Update System.Blockchain.GetTransactionHeight and removed
Neo.Blockchain.GetTransactionHeight interop as we don't need it.
Removed Neo.Block.GetTransaction and System.Block.GetTransaction
interops. These interops were replaced by new
System.Blockchain.GetTransactionFromBlock interop.
closes #1025

Now we put on stack stackitem.Array instead of Interop, so we're able to
use all available block properties without extra interop getters.
Removed Neo.Blockchain.GetBlock interop as we don't need it anymore.
Updated System.Blockchain.GetBlock interop replaced the functionality of
the following interops:
	System.Block.GetTransactions
	System.Block.GetTransactionCount
	Neo.Block.GetTransactions
	Neo.Block.GetTransactionsCount
@roman-khimov roman-khimov merged commit 851e72f into master Jun 10, 2020
@roman-khimov roman-khimov deleted the neo3/interop/gettransaction branch June 10, 2020 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement new System.Blockchain.GetTransaction interop
3 participants