-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-1639] [FAB-1580] Rework validator
This change-set has removed calls to the txvalidator that were issued right after the peer (the leader) receives blocks from the orderers. The validator is now called to validate messages received from the gossip layer. In order to fix an import cycle, we have introduced the ChaincodeProvider interface in core/common/ccprovider/ccprovider.go, an implementation and a factory. This way, code that needs to use functions from the chaincode package without importing it can simply use (and possibly extend) the ChaincodeProvider interface and implementation. Furthermore, this drop has introduced protocol-level message validation for config transactions that was lacking before. Change-Id: I5906a6fe3da8410b05b5079dd7f0b9d28d20bb85 Signed-off-by: Alessandro Sorniotti <[email protected]>
- Loading branch information
Showing
23 changed files
with
431 additions
and
93 deletions.
There are no files selected for viewing
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,81 @@ | ||
package chaincode | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hyperledger/fabric/core/common/ccprovider" | ||
"github.com/hyperledger/fabric/core/ledger" | ||
"github.com/hyperledger/fabric/protos/peer" | ||
) | ||
|
||
// ccProviderFactory implements the ccprovider.ChaincodeProviderFactory | ||
// interface and returns instances of ccprovider.ChaincodeProvider | ||
type ccProviderFactory struct { | ||
} | ||
|
||
// NewChaincodeProvider returns pointers to ccProviderImpl as an | ||
// implementer of the ccprovider.ChaincodeProvider interface | ||
func (c *ccProviderFactory) NewChaincodeProvider() ccprovider.ChaincodeProvider { | ||
return &ccProviderImpl{} | ||
} | ||
|
||
// init is called when this package is loaded. This implementation registers the factory | ||
func init() { | ||
ccprovider.RegisterChaincodeProviderFactory(&ccProviderFactory{}) | ||
} | ||
|
||
// ccProviderImpl is an implementation of the ccprovider.ChaincodeProvider interface | ||
type ccProviderImpl struct { | ||
txsim ledger.TxSimulator | ||
} | ||
|
||
// ccProviderContextImpl contains the state that is passed around to calls to methods of ccProviderImpl | ||
type ccProviderContextImpl struct { | ||
ctx *CCContext | ||
} | ||
|
||
// GetContext returns a context for the supplied ledger, with the appropriate tx simulator | ||
func (c *ccProviderImpl) GetContext(ledger ledger.ValidatedLedger) (context.Context, error) { | ||
var err error | ||
// get context for the chaincode execution | ||
c.txsim, err = ledger.NewTxSimulator() | ||
if err != nil { | ||
return nil, err | ||
} | ||
ctxt := context.WithValue(context.Background(), TXSimulatorKey, c.txsim) | ||
return ctxt, nil | ||
} | ||
|
||
// GetCCContext returns an interface that encapsulates a | ||
// chaincode context; the interface is required to avoid | ||
// referencing the chaincode package from the interface definition | ||
func (c *ccProviderImpl) GetCCContext(cid, name, version, txid string, syscc bool, prop *peer.Proposal) interface{} { | ||
ctx := NewCCContext(cid, name, version, txid, syscc, prop) | ||
return &ccProviderContextImpl{ctx: ctx} | ||
} | ||
|
||
// GetVSCCFromLCCC returns the VSCC listed in LCCC for the supplied chaincode | ||
func (c *ccProviderImpl) GetVSCCFromLCCC(ctxt context.Context, txid string, prop *peer.Proposal, chainID string, chaincodeID string) (string, error) { | ||
data, err := GetChaincodeDataFromLCCC(ctxt, txid, prop, chainID, chaincodeID) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
vscc := "vscc" | ||
// Check whenever VSCC defined for chaincode data | ||
if data != nil && data.Vscc != "" { | ||
vscc = data.Vscc | ||
} | ||
|
||
return vscc, nil | ||
} | ||
|
||
// ExecuteChaincode executes the chaincode specified in the context with the specified arguments | ||
func (c *ccProviderImpl) ExecuteChaincode(ctxt context.Context, cccid interface{}, args [][]byte) ([]byte, *peer.ChaincodeEvent, error) { | ||
return ExecuteChaincode(ctxt, cccid.(*ccProviderContextImpl).ctx, args) | ||
} | ||
|
||
// ReleaseContext frees up resources held by the context | ||
func (c *ccProviderImpl) ReleaseContext() { | ||
c.txsim.Done() | ||
} |
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
Oops, something went wrong.